Skip to content

Commit

Permalink
Always show cursor when deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
qwbarch committed Dec 10, 2023
1 parent ff8dc64 commit 92b3509
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
, dependencies =
[ "aff"
, "arrays"
, "console"
, "css"
, "datetime"
, "effect"
Expand Down
11 changes: 9 additions & 2 deletions src/Halogen/Typewriter.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ import Prelude hiding (div)
import CSS (opacity)
import Control.Monad.State (get, modify)
import Data.Foldable (fold)
import Data.Generic.Rep (class Generic)
import Data.Lens (view, (%=), (.=), (<>=))
import Data.List.Lazy (List, head, tail)
import Data.Maybe (Maybe(..))
import Data.Newtype (unwrap)
import Data.Show.Generic (genericShow)
import Data.String (null, take)
import Data.String.CodeUnits (charAt, length, singleton)
import Data.Time.Duration (Milliseconds(..))
import Effect (Effect)
import Effect.Aff (delay, forkAff)
import Effect.Aff.Class (class MonadAff, liftAff)
import Effect.Class (liftEffect)
import Effect.Class.Console (log)
import Effect.Random (randomRange)
import Halogen (ClassName(..), Component, ComponentHTML, defaultEval, mkComponent, mkEval, raise, subscribe)
import Halogen.HTML (span, text)
Expand Down Expand Up @@ -78,6 +81,9 @@ data Mode
-- | The typewriter is currently deleting letters.
| Deleting

derive instance eqMode :: Eq Mode
derive instance genericMode :: Generic Mode _

-- | Internal actions for 'typewriter'.
data Action
-- | Start the 'typewriter'. This should only be invoked internally.
Expand Down Expand Up @@ -152,7 +158,8 @@ typewriter = mkComponent { initialState, render, eval }
forkDispatch UpdateState
UpdateCursor -> get >>= \state ->
when state.running $ do
cursorHidden %= not
when (state.mode == Typing) $
cursorHidden %= not
sleep identity cursorDelay
handleAction UpdateCursor
UpdateState -> get >>= \state ->
Expand All @@ -168,8 +175,8 @@ typewriter = mkComponent { initialState, render, eval }
Nothing -> do
-- Delete the current word from state.words.
words %= fold <<< tail
mode .= Deleting
sleep identity pauseDelay
void $ modify $ _ { mode = Deleting, cursorHidden = false }
Just letter -> do
coefficient <- liftEffect state.jitter
sleep (_ * coefficient) typeDelay
Expand Down

0 comments on commit 92b3509

Please sign in to comment.