Class TUI
java.lang.Object
it.polimi.ingsw.gc14.View.TUI.TUI
- All Implemented Interfaces:
IView
Text-based User Interface (TUI) implementation of
IView.
Single render view: board + menu on top, all players' hands in a responsive grid below. Hands wrap to a new row when their combined width would exceed the terminal width.
All output goes through display(String), which uses
LineReader.printAbove(String) when a JLine reader is set so that the
readline prompt is correctly redrawn after background-thread renders.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.jline.reader.LineReaderJLine reader — when non-null, all output usesprintAboveso the readline prompt is preserved after background-thread renders.private MiniModelprivate org.jline.terminal.TerminalJLine terminal — used to query terminal width for centering and grid layout.private String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the board state as a multi-line string: turn order, upper cards, offer track, lower cards.private StringArranges every player's hand side-by-side, wrapping to a new grid row whenever the next panel would exceed the terminal width.private StringBuilds the main view: board + menu side by side, followed by all players' hands arranged in a responsive grid.private Stringprivate Stringprivate StringHorizontally centers each line ofcontentwithin the terminal width.private voidClears the terminal and displayscontent, horizontally centered.private voidPrintstextabove the prompt without clearing the screen.voidrender()Default render: dispatches to the right view based on game stage.voidRenders the board + menu (top) and all players' hands in a grid (bottom).voidsetLineReader(org.jline.reader.LineReader lineReader) Registers the active JLineLineReader.voidUpdates the model stored in this view.voidsetUsername(String username) Sets the username of the local player.voidShows an error message combined with the current board in one display call, so only oneprintAboveis issued and the prompt is redrawn correctly.private intvisibleLength(String line) Returns the display width of a string in terminal columns, stripping ANSI escape codes.
-
Field Details
-
model
-
username
-
lineReader
private org.jline.reader.LineReader lineReaderJLine reader — when non-null, all output usesprintAboveso the readline prompt is preserved after background-thread renders. -
terminal
private org.jline.terminal.Terminal terminalJLine terminal — used to query terminal width for centering and grid layout.
-
-
Constructor Details
-
TUI
Constructs aTUIbound to the given model.- Parameters:
model- the model to display; may benullinitially.
-
-
Method Details
-
setUsername
Sets the username of the local player.- Parameters:
username- the username to assign.
-
setModel
-
setLineReader
public void setLineReader(org.jline.reader.LineReader lineReader) Registers the active JLineLineReader. Once set, all output routes throughLineReader.printAbove(String)so the prompt survives background-thread renders.- Parameters:
lineReader- the JLine reader to use for output; also provides the terminal reference.
-
render
-
renderBoard
public void renderBoard()Renders the board + menu (top) and all players' hands in a grid (bottom). -
showError
Shows an error message combined with the current board in one display call, so only oneprintAboveis issued and the prompt is redrawn correctly. -
buildBoardContent
Builds the main view: board + menu side by side, followed by all players' hands arranged in a responsive grid. -
buildAllHandsContent
Arranges every player's hand side-by-side, wrapping to a new grid row whenever the next panel would exceed the terminal width. -
buildTotemsContent
-
buildStandingContent
-
display
Clears the terminal and displayscontent, horizontally centered.When a JLine
LineReaderis registered, output is routed throughLineReader.printAbove(String)which pauses readline, prints the content, and redraws the prompt — safe to call from any thread. Otherwise, ANSI codes are written directly to stdout. -
printLine
Printstextabove the prompt without clearing the screen. -
center
-
visibleLength
Returns the display width of a string in terminal columns, stripping ANSI escape codes. -
boardStamp
Returns the board state as a multi-line string: turn order, upper cards, offer track, lower cards.- Returns:
- multi-line board string.
-