Package net.thevpc.naru.impl.interaction
Class NaruTerminalInteraction
java.lang.Object
net.thevpc.naru.impl.interaction.NaruTerminalInteraction
- All Implemented Interfaces:
NaruInteraction
The desktop implementation: a real terminal, a real readline thread.
This is where presentation lives. Indentation, the ▌ gutter, and the per-mode
colour scheme were previously in NaruAgentImpl.log, where they applied to every
session at once; they are here now, so a headless session emitting the same events gets
plain text and no ANSI escapes.
Why a thread at all
requestInput(net.thevpc.naru.api.agent.NaruInputRequest) is called on a scheduler worker that must not block, so the read
is pushed onto a dedicated thread. That thread parks on a queue and only touches the
terminal while a question is outstanding, which is what lets a batch session coexist
with a console in the same process.
Streams are the host's choice
The terminal defaults to the process one, but two interactive sessions cannot share a single stdin — whoever reads first wins. A host that needs two live consoles passes distinct streams to the constructor instead.-
Field Summary
Fields inherited from interface net.thevpc.naru.api.agent.NaruInteraction
NAME_STREAM, NAME_TERMINAL -
Constructor Summary
ConstructorsConstructorDescriptionUses the process terminal, writing through the terminal's own out.NaruTerminalInteraction(net.thevpc.nuts.io.NTerminal terminal) NaruTerminalInteraction(net.thevpc.nuts.io.NTerminal terminal, net.thevpc.nuts.log.NLogger logger) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()name()voidopen(NaruSession session) voidrequestInput(NaruInputRequest request) voidwrite(NaruLogMode mode, net.thevpc.nuts.text.NMsg message) voidwriteStream(NaruLogMode mode, net.thevpc.nuts.text.NMsg fragment, boolean end) Draws a fragment as it arrives, so a long answer appears while it is being written rather than all at once when it is finished.
-
Constructor Details
-
NaruTerminalInteraction
public NaruTerminalInteraction()Uses the process terminal, writing through the terminal's own out. -
NaruTerminalInteraction
public NaruTerminalInteraction(net.thevpc.nuts.io.NTerminal terminal) -
NaruTerminalInteraction
public NaruTerminalInteraction(net.thevpc.nuts.io.NTerminal terminal, net.thevpc.nuts.log.NLogger logger) - Parameters:
terminal- the terminal to read from and write to; null means the process onelogger- where styled output goes; null means the terminal's own out
-
-
Method Details
-
name
- Specified by:
namein interfaceNaruInteraction
-
open
- Specified by:
openin interfaceNaruInteraction
-
requestInput
- Specified by:
requestInputin interfaceNaruInteraction
-
write
- Specified by:
writein interfaceNaruInteraction
-
writeStream
Draws a fragment as it arrives, so a long answer appears while it is being written rather than all at once when it is finished.Each physical line is prefixed exactly as
render(net.thevpc.naru.api.agent.NaruLogMode, net.thevpc.nuts.text.NMsg)would prefix it, so a streamed answer and a batched one are indented identically. The content itself is printed unstyled: markdown cannot be rendered on a fragment, because half a code fence or an unmatched**is not markup, it is noise.- Specified by:
writeStreamin interfaceNaruInteraction
-
close
public void close()- Specified by:
closein interfaceNaruInteraction
-