java.lang.Object
org.jline.shell.CommandSession
Encapsulates the execution context for a command, including the terminal,
I/O streams, session variables, working directory, and job state.
- Since:
- 4.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new command session with the system's standard I/O streams.CommandSession(org.jline.terminal.Terminal terminal) Creates a new command session with the specified terminal.CommandSession(org.jline.terminal.Terminal terminal, InputStream in, PrintStream out, PrintStream err) Creates a new command session with the specified terminal and I/O streams. -
Method Summary
Modifier and TypeMethodDescriptionerr()Returns the error stream.Returns the current foreground job.fork(InputStream in, PrintStream out, PrintStream err) Creates a child session that shares the same terminal but uses independent I/O streams.Returns the value of a session variable.in()Returns the input stream.intReturns the exit code of the last executed command.out()Returns the output stream.voidSets a session variable.Removes a session variable.voidsetErr(PrintStream err) Sets the error stream.voidsetForegroundJob(Job foregroundJob) Sets the current foreground job.voidsetIn(InputStream in) Sets the input stream.voidsetLastExitCode(int lastExitCode) Sets the exit code of the last executed command.voidsetOut(PrintStream out) Sets the output stream.voidsetWorkingDirectory(Path workingDirectory) Sets the working directory.org.jline.terminal.Terminalterminal()Returns the terminal for this session.Returns all session variables.Returns the working directory.
-
Constructor Details
-
CommandSession
public CommandSession()Creates a new command session with the system's standard I/O streams. The terminal will be null. -
CommandSession
public CommandSession(org.jline.terminal.Terminal terminal) Creates a new command session with the specified terminal. I/O streams are derived from the terminal.- Parameters:
terminal- the terminal
-
CommandSession
public CommandSession(org.jline.terminal.Terminal terminal, InputStream in, PrintStream out, PrintStream err) Creates a new command session with the specified terminal and I/O streams.- Parameters:
terminal- the terminalin- the input streamout- the output streamerr- the error stream
-
-
Method Details
-
terminal
public org.jline.terminal.Terminal terminal()Returns the terminal for this session.- Returns:
- the terminal, or null if not associated
-
in
Returns the input stream.- Returns:
- the input stream
-
out
Returns the output stream.- Returns:
- the output stream
-
setOut
Sets the output stream.- Parameters:
out- the new output stream
-
setIn
Sets the input stream.- Parameters:
in- the new input stream
-
err
Returns the error stream.- Returns:
- the error stream
-
setErr
Sets the error stream.- Parameters:
err- the new error stream
-
get
Returns the value of a session variable.- Parameters:
name- the variable name- Returns:
- the value, or null if not set
-
put
Sets a session variable.- Parameters:
name- the variable namevalue- the value
-
remove
Removes a session variable.- Parameters:
name- the variable name- Returns:
- the previous value, or null if not set
-
variables
Returns all session variables.- Returns:
- unmodifiable view of the variables
-
workingDirectory
Returns the working directory.- Returns:
- the working directory, or null
-
setWorkingDirectory
Sets the working directory.- Parameters:
workingDirectory- the working directory
-
lastExitCode
public int lastExitCode()Returns the exit code of the last executed command.- Returns:
- the last exit code
-
setLastExitCode
public void setLastExitCode(int lastExitCode) Sets the exit code of the last executed command.- Parameters:
lastExitCode- the exit code
-
foregroundJob
Returns the current foreground job.- Returns:
- the foreground job, or null
-
setForegroundJob
Sets the current foreground job.- Parameters:
foregroundJob- the foreground job
-
fork
Creates a child session that shares the same terminal but uses independent I/O streams.The child session gets a copy of the current variables and working directory. This is used for concurrent pipeline execution where each stage needs its own I/O streams.
- Parameters:
in- the input stream for the child sessionout- the output stream for the child sessionerr- the error stream for the child session- Returns:
- a new child session
-