Package xyz.cofe.term.common.nix
Class NixAsyncConsole
- java.lang.Object
-
- xyz.cofe.term.common.nix.NixAbstractConsole
-
- xyz.cofe.term.common.nix.NixConsole
-
- xyz.cofe.term.common.nix.NixAsyncConsole
-
- All Implemented Interfaces:
AutoCloseable,Console
public class NixAsyncConsole extends NixConsole
Консоль с асинхронным чтением входных данных. При обычном чтении (NixConsole) - медленно.-
Создает отдельный поток для чтения нажатий клавиш/мыши и других входных данных.
Копирует события во внутренюю очередь
Данные читаются при помощиreadSync() -
Создает очередь для чтения входных из основного потока исполнения.
Из очереди данные читаются при помощиread() - Фоноый поток помечен как daemon и уничтожается либо при вызове close либо при завершении работы jvm
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classNixAsyncConsole.InputReader
-
Field Summary
Fields Modifier and Type Field Description protected ReadWriteLockcloseLockprotected NixAsyncConsole.InputReaderreaderThread-
Fields inherited from class xyz.cofe.term.common.nix.NixConsole
eventBuffer, limitMouseActions, mouseActions, terminal
-
Fields inherited from class xyz.cofe.term.common.nix.NixAbstractConsole
closed
-
-
Constructor Summary
Constructors Constructor Description NixAsyncConsole(com.googlecode.lanterna.terminal.ExtendedTerminal terminal)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected Queue<InputEvent>createEventQueue()protected List<com.googlecode.lanterna.input.MouseAction>createHistory()PositiongetCursorPosition()Возвращает позицию курсораSizegetSize()Возвращает размер терминалаprotected voidlock(boolean write, Runnable code)protected <R> Rlock(boolean write, Supplier<R> code)protected voidlockRead(Runnable code)protected <R> RlockRead(Supplier<R> code)Optional<InputEvent>read()Чтение событие вводаprotected Optional<InputEvent>read(com.googlecode.lanterna.input.KeyStroke ks)Optional<InputEvent>readSync()Синхронное-блокируемое чтение данныхvoidsetBackground(Color color)Устанавливает цвет фонаvoidsetCursorPosition(int x, int y)Устанавливает позицию курсораvoidsetCursorPosition(Position position)Устанавливает позицию курсораvoidsetCursorVisible(boolean visible)Установить видимость курсораvoidsetForeground(Color color)Устанавливает цвет текстаvoidsetSize(Size size)Устанавливает размер терминалаvoidsetTitle(String title)Устанавливает заголовокvoidwrite(String text)Запись текста в позицию курсора-
Methods inherited from class xyz.cofe.term.common.nix.NixConsole
mouseHistory, pollFromQueue, putToQueue, terminal
-
Methods inherited from class xyz.cofe.term.common.nix.NixAbstractConsole
close, init, terminal
-
-
-
-
Field Detail
-
readerThread
protected final NixAsyncConsole.InputReader readerThread
-
closeLock
protected final ReadWriteLock closeLock
-
-
Method Detail
-
lock
protected <R> R lock(boolean write, Supplier<R> code)
-
lock
protected void lock(boolean write, Runnable code)
-
lockRead
protected <R> R lockRead(Supplier<R> code)
-
lockRead
protected void lockRead(Runnable code)
-
createEventQueue
protected Queue<InputEvent> createEventQueue()
- Overrides:
createEventQueuein classNixConsole
-
createHistory
protected List<com.googlecode.lanterna.input.MouseAction> createHistory()
- Overrides:
createHistoryin classNixConsole
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classNixConsole- Throws:
Exception
-
setTitle
public void setTitle(String title)
Description copied from interface:ConsoleУстанавливает заголовок- Specified by:
setTitlein interfaceConsole- Overrides:
setTitlein classNixAbstractConsole- Parameters:
title- заголовок
-
getCursorPosition
public Position getCursorPosition()
Description copied from interface:ConsoleВозвращает позицию курсора- Specified by:
getCursorPositionin interfaceConsole- Overrides:
getCursorPositionin classNixAbstractConsole- Returns:
- позиция курсора
-
setCursorPosition
public void setCursorPosition(Position position)
Description copied from interface:ConsoleУстанавливает позицию курсора- Specified by:
setCursorPositionin interfaceConsole- Overrides:
setCursorPositionin classNixAbstractConsole- Parameters:
position- позиция курсора
-
setCursorPosition
public void setCursorPosition(int x, int y)Description copied from interface:ConsoleУстанавливает позицию курсора- Specified by:
setCursorPositionin interfaceConsole- Overrides:
setCursorPositionin classNixAbstractConsole- Parameters:
x- координатыy- координаты
-
getSize
public Size getSize()
Description copied from interface:ConsoleВозвращает размер терминала- Specified by:
getSizein interfaceConsole- Overrides:
getSizein classNixAbstractConsole- Returns:
- размер терминала
-
setSize
public void setSize(Size size)
Description copied from interface:ConsoleУстанавливает размер терминала- Specified by:
setSizein interfaceConsole- Overrides:
setSizein classNixAbstractConsole- Parameters:
size- размер терминала
-
setForeground
public void setForeground(Color color)
Description copied from interface:ConsoleУстанавливает цвет текста- Specified by:
setForegroundin interfaceConsole- Overrides:
setForegroundin classNixAbstractConsole- Parameters:
color- цвет
-
setBackground
public void setBackground(Color color)
Description copied from interface:ConsoleУстанавливает цвет фона- Specified by:
setBackgroundin interfaceConsole- Overrides:
setBackgroundin classNixAbstractConsole- Parameters:
color- цвет
-
setCursorVisible
public void setCursorVisible(boolean visible)
Description copied from interface:ConsoleУстановить видимость курсора- Specified by:
setCursorVisiblein interfaceConsole- Overrides:
setCursorVisiblein classNixAbstractConsole- Parameters:
visible- true - курсор видим
-
read
public Optional<InputEvent> read()
Description copied from interface:ConsoleЧтение событие ввода- Specified by:
readin interfaceConsole- Overrides:
readin classNixAbstractConsole- Returns:
- событие
-
readSync
public Optional<InputEvent> readSync()
Description copied from class:NixAbstractConsoleСинхронное-блокируемое чтение данных- Overrides:
readSyncin classNixAbstractConsole- Returns:
- прочитанное значение
-
write
public void write(String text)
Description copied from interface:ConsoleЗапись текста в позицию курсора- Specified by:
writein interfaceConsole- Overrides:
writein classNixAbstractConsole- Parameters:
text- текст
-
read
protected Optional<InputEvent> read(com.googlecode.lanterna.input.KeyStroke ks)
- Overrides:
readin classNixAbstractConsole
-
-