- java.lang.Object
-
- org.jline.shell.CommandSession
-
public class CommandSession extends java.lang.ObjectEncapsulates the execution context for a command, including the terminal, I/O streams, session variables, working directory, and job state.- Since:
- 4.0
- See Also:
Command.execute(CommandSession, String[])
-
-
Constructor Summary
Constructors Constructor Description CommandSession()Creates 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, java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err)Creates a new command session with the specified terminal and I/O streams.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.PrintStreamerr()Returns the error stream.JobforegroundJob()Returns the current foreground job.CommandSessionfork(java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err)Creates a child session that shares the same terminal but uses independent I/O streams.java.lang.Objectget(java.lang.String name)Returns the value of a session variable.java.io.InputStreamin()Returns the input stream.intlastExitCode()Returns the exit code of the last executed command.java.io.PrintStreamout()Returns the output stream.voidput(java.lang.String name, java.lang.Object value)Sets a session variable.java.lang.Objectremove(java.lang.String name)Removes a session variable.voidsetErr(java.io.PrintStream err)Sets the error stream.voidsetForegroundJob(Job foregroundJob)Sets the current foreground job.voidsetIn(java.io.InputStream in)Sets the input stream.voidsetLastExitCode(int lastExitCode)Sets the exit code of the last executed command.voidsetOut(java.io.PrintStream out)Sets the output stream.voidsetWorkingDirectory(java.nio.file.Path workingDirectory)Sets the working directory.org.jline.terminal.Terminalterminal()Returns the terminal for this session.java.util.Map<java.lang.String,java.lang.Object>variables()Returns all session variables.java.nio.file.PathworkingDirectory()Returns the working directory.
-
-
-
Constructor Detail
-
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, java.io.InputStream in, java.io.PrintStream out, java.io.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 Detail
-
terminal
public org.jline.terminal.Terminal terminal()
Returns the terminal for this session.- Returns:
- the terminal, or null if not associated
-
in
public java.io.InputStream in()
Returns the input stream.- Returns:
- the input stream
-
out
public java.io.PrintStream out()
Returns the output stream.- Returns:
- the output stream
-
setOut
public void setOut(java.io.PrintStream out)
Sets the output stream.- Parameters:
out- the new output stream
-
setIn
public void setIn(java.io.InputStream in)
Sets the input stream.- Parameters:
in- the new input stream
-
err
public java.io.PrintStream err()
Returns the error stream.- Returns:
- the error stream
-
setErr
public void setErr(java.io.PrintStream err)
Sets the error stream.- Parameters:
err- the new error stream
-
get
public java.lang.Object get(java.lang.String name)
Returns the value of a session variable.- Parameters:
name- the variable name- Returns:
- the value, or null if not set
-
put
public void put(java.lang.String name, java.lang.Object value)Sets a session variable.- Parameters:
name- the variable namevalue- the value
-
remove
public java.lang.Object remove(java.lang.String name)
Removes a session variable.- Parameters:
name- the variable name- Returns:
- the previous value, or null if not set
-
variables
public java.util.Map<java.lang.String,java.lang.Object> variables()
Returns all session variables.- Returns:
- unmodifiable view of the variables
-
workingDirectory
public java.nio.file.Path workingDirectory()
Returns the working directory.- Returns:
- the working directory, or null
-
setWorkingDirectory
public void setWorkingDirectory(java.nio.file.Path workingDirectory)
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
public Job foregroundJob()
Returns the current foreground job.- Returns:
- the foreground job, or null
-
setForegroundJob
public void setForegroundJob(Job foregroundJob)
Sets the current foreground job.- Parameters:
foregroundJob- the foreground job
-
fork
public CommandSession fork(java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err)
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
-
-