Skip to content

Commit

Permalink
charm cursor: don't exit on eof
Browse files Browse the repository at this point in the history
charm cursor is meant to be more of a "watcher" it shouldn't choose any particular action on Eof, instead it can just return "unhandled". when in a parallel state, this will cause it to be dropped ( where previously it would have forced a terminal transition ) -- but at Eof the machine is exiting, so that's fine.
  • Loading branch information
ionous committed Jul 20, 2024
1 parent e81f218 commit d022889
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions charm/charmParallel.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package charm

// Parallel region; run all of the passed states until they all return nil.
// if any return error, this returns error.
// Run all of the passed states.
// If any return nil, they are dropped;
// If any return Terminal ( ex. via Error() or Finished() )
// the parallel state exits.
func Parallel(name string, rs ...State) State {
return Self(name, func(self State, r rune) (ret State) {
var cnt int
Loop:
for _, s := range rs {
switch next := s.NewRune(r); next.(type) {
case nil:
// skip
// this drops the state from the update list
case Terminal:
ret = next
break Loop
Expand Down
2 changes: 1 addition & 1 deletion charmed/charmedCursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func DecodePos(y, x *int) charm.State {
return charm.Self("cursor", func(self charm.State, q rune) (ret charm.State) {
switch q {
case runes.Eof:
ret = charm.Finished() // absorb
ret = nil // return unhandled; in a parallel state this stops updating
case runes.Newline:
(*y)++
(*x) = 0
Expand Down

0 comments on commit d022889

Please sign in to comment.