1515
1616
1717class Consoler (doing .Doer ):
18- """
19- Manages command console
18+ """Manages a command-line serial console
19+
20+ Reads lines from a serial console, parses simple movement commands,
21+ and echoes feedback. Inherits lifecycle management (enter/recur/exit)
22+ from :class:`hio.base.doing.Doer`.
23+
24+ Attributes:
25+ db (Baser): Database instance used by this doer.
26+ console (serialing.Console): Serial console for input/output.
2027 """
2128
2229 def __init__ (self , db = None , console = None , ** kwa ):
23- """
24-
30+ """Initializes Consoler with optional database and console.
31+
32+ Args:
33+ db (Baser, optional): Database instance. Defaults to a new
34+ :class:`~keri.db.basing.Baser` instance if None.
35+ console (serialing.Console, optional): Serial console instance.
36+ Defaults to a new :class:`~hio.core.serial.serialing.Console`
37+ instance if None.
38+ **kwa: Additional keyword arguments passed to
39+ :class:`~hio.base.doing.Doer`.
2540 """
2641 super (Consoler , self ).__init__ (** kwa )
2742 self .db = db if db is not None else Baser ()
2843 self .console = console if console is not None else serialing .Console ()
2944
3045 def enter (self , * , temp = None ):
31- """"""
32- if not self .console .reopen (): # reopen(temp=temp)
33- raise IOError ("Unable to open serial console." )
46+ """Opens the serial console resource.
3447
35- def recur (self , tyme ):
48+ Called by the Doer framework when entering the task context.
49+
50+ Args:
51+ temp (bool, optional): Unused. Reserved for interface compatibility.
52+
53+ Raises:
54+ IOError: If the console cannot be opened.
3655 """
37- Do 'recur' context actions. Override in subclass.
38- Regular method that perform repetitive actions once per invocation.
39- Assumes resource setup in .enter() and resource takedown in .exit()
40- (see ReDoer below for example of .recur that is a generator method)
56+ if not self .console .reopen ():
57+ raise IOError ("Unable to open serial console." )
4158
42- Returns completion state of recurrence actions.
43- True means done False means continue
59+ def recur ( self , tyme ):
60+ """Reads one line from the console and dispatches a movement command.
4461
45- Parameters:
46- Doist feeds its .tyme through .send to .do yield which passes it here.
62+ Recognized commands (matched on the first character, case-insensitive):
4763
64+ - ``r`` / ``right``: turn right
65+ - ``l`` / ``left``: turn left
66+ - ``w`` / ``walk``: walk 1 step
67+ - ``s`` / ``stop``: stop
4868
49- .recur maybe implemented by a subclass either as a non-generator method
50- or a generator method. This stub here is as a non-generator method.
51- The base class .do detects which type:
52- If non-generator .do method runs .recur method once per iteration
53- until .recur returns (True)
54- If generator .do method runs .recur with (yield from) until .recur
55- returns (see ReDoer for example of generator .recur)
69+ Args:
70+ tyme (float): Current loop time provided by the Doist scheduler.
5671
72+ Returns:
73+ bool: Always ``False``; signals the Doer to continue recurring.
5774 """
58- line = self .console .get () # process one line of input
75+ line = self .console .get ()
5976 if not line :
6077 return False
6178 chunks = line .lower ().split ()
6279
63- # args = parser.parse_args(chunks)
64- # if hasattr(args, "handler"):
65- # args.handler(args)
66-
67- if not chunks : # empty list
80+ if not chunks :
6881 self .console .put ("Try one of: l[eft] r[ight] w[alk] s[top]\n " )
6982 return False
7083 verb = chunks [0 ]
@@ -91,5 +104,8 @@ def recur(self, tyme):
91104 return False
92105
93106 def exit (self ):
94- """"""
107+ """Closes the serial console resource.
108+
109+ Called by the Doer framework when leaving the task context.
110+ """
95111 self .console .close ()
0 commit comments