Class NaruTerminalInteraction

java.lang.Object
net.thevpc.naru.impl.interaction.NaruTerminalInteraction
All Implemented Interfaces:
NaruInteraction

public class NaruTerminalInteraction extends Object implements 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.
  • 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 one
      logger - where styled output goes; null means the terminal's own out
  • Method Details

    • name

      public String name()
      Specified by:
      name in interface NaruInteraction
    • open

      public void open(NaruSession session)
      Specified by:
      open in interface NaruInteraction
    • requestInput

      public void requestInput(NaruInputRequest request)
      Specified by:
      requestInput in interface NaruInteraction
    • write

      public void write(NaruLogMode mode, net.thevpc.nuts.text.NMsg message)
      Specified by:
      write in interface NaruInteraction
    • writeStream

      public void writeStream(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.

      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:
      writeStream in interface NaruInteraction
    • close

      public void close()
      Specified by:
      close in interface NaruInteraction