Documentation
¶
Overview ¶
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Index ¶
- Constants
- type AnsiEscape
- type Canvas
- type FormattedTable
- func (p *FormattedTable) Format(col uint, row uint, escape AnsiEscape)
- func (p *FormattedTable) Height() uint
- func (p *FormattedTable) Print(escapes bool)
- func (p *FormattedTable) Set(col uint, row uint, val FormattedText)
- func (p *FormattedTable) SetMaxWidth(col uint, width uint)
- func (p *FormattedTable) SetMaxWidths(width uint)
- func (p *FormattedTable) SetRow(row uint, vals ...FormattedText)
- func (p *FormattedTable) Sort(start uint, sorter TableSorter)
- func (p *FormattedTable) Text(col uint, row uint) string
- type FormattedText
- type TableSorter
- type Terminal
- type Widget
- type Window
Constants ¶
const BACKSPACE uint16 = 0x08
BACKSPACE is the backspace
const BACKTAB uint16 = 0x5b5a
BACKTAB indicates shift + tab
const CARRIAGE_RETURN uint16 = 0x0D
CARRIAGE_RETURN indicates "enter"
const CURSOR_DOWN uint16 = 0x5b42
CURSOR_DOWN (down arrow)
const CURSOR_LEFT uint16 = 0x5b43
CURSOR_LEFT (left arrow)
const CURSOR_RIGHT uint16 = 0x5b44
CURSOR_RIGHT (left arrow)
const CURSOR_UP uint16 = 0x5b41
CURSOR_UP (up arrow)
const DEL uint16 = 0x7f
DEL is the delete key
const ESC uint16 = 0x1b
ESC is the escape code.
const SCROLL_DOWN uint16 = 0x5b54
SCROLL_DOWN (page down)
const SCROLL_UP uint16 = 0x5b53
SCROLL_UP (page up)
const TAB uint16 = 0x09
TAB indicates the horizontal tab
const TERM_BLACK = uint(0)
TERM_BLACK represents black
const TERM_BLUE = uint(4)
TERM_BLUE represents blue
const TERM_CYAN = uint(6)
TERM_CYAN represents cyan
const TERM_GREEN = uint(2)
TERM_GREEN represents green
const TERM_MAGENTA = uint(5)
TERM_MAGENTA represents magenta
const TERM_RED = uint(1)
TERM_RED represents red
const TERM_WHITE = uint(7)
TERM_WHITE represents white
const TERM_YELLOW = uint(3)
TERM_YELLOW represents yellow
const UNKNOWN uint16 = 0x5bff
UNKNOWN is a fall-back for unknown escape sequences
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnsiEscape ¶
type AnsiEscape struct {
// contains filtered or unexported fields
}
AnsiEscape represents an ANSI escape code used for formatting text in a terminal.
func UnderlineAnsiEscape ¶
func UnderlineAnsiEscape() AnsiEscape
UnderlineAnsiEscape constructs a reset term.
func (AnsiEscape) Bg256Colour ¶
func (p AnsiEscape) Bg256Colour(col uint) AnsiEscape
Bg256Colour sets the background colour using 256-colour mode.
func (AnsiEscape) BgColour ¶
func (p AnsiEscape) BgColour(col uint) AnsiEscape
BgColour sets the foreground colour
func (AnsiEscape) Fg256Colour ¶
func (p AnsiEscape) Fg256Colour(col uint) AnsiEscape
Fg256Colour sets the foreground colour using 256-colour mode.
func (AnsiEscape) FgColour ¶
func (p AnsiEscape) FgColour(col uint) AnsiEscape
FgColour sets the foreground colour
type Canvas ¶
type Canvas interface {
// Get the dimensions of this canvas.
GetDimensions() (uint, uint)
// Write a chunk to the canvas.
Write(x, y uint, text FormattedText)
}
Canvas represents a surface on which widgets can draw.
type FormattedTable ¶ added in v1.0.7
type FormattedTable struct {
// contains filtered or unexported fields
}
FormattedTable is useful for printing tables to the terminal.
func NewFormattedTable ¶ added in v1.1.24
func NewFormattedTable(width uint, height uint) *FormattedTable
NewFormattedTable constructs a new table with given dimensions.
func (*FormattedTable) Format ¶ added in v1.0.7
func (p *FormattedTable) Format(col uint, row uint, escape AnsiEscape)
Format the contents of a given cell in this table
func (*FormattedTable) Height ¶ added in v1.0.7
func (p *FormattedTable) Height() uint
Height returns the height of this table.
func (*FormattedTable) Print ¶ added in v1.0.7
func (p *FormattedTable) Print(escapes bool)
Print the table with or without the use of ANSI escapes (e.g. for showing colour). Disabling escapes is useful in environments that don't support escapes as, otherwise, you get a lot of visible excape characters being printed.
func (*FormattedTable) Set ¶ added in v1.0.7
func (p *FormattedTable) Set(col uint, row uint, val FormattedText)
Set the contents of a given cell in this table
func (*FormattedTable) SetMaxWidth ¶ added in v1.0.7
func (p *FormattedTable) SetMaxWidth(col uint, width uint)
SetMaxWidth puts an upper bound on the width of any column.
func (*FormattedTable) SetMaxWidths ¶ added in v1.0.7
func (p *FormattedTable) SetMaxWidths(width uint)
SetMaxWidths puts an upper bound on the width of any column.
func (*FormattedTable) SetRow ¶ added in v1.0.7
func (p *FormattedTable) SetRow(row uint, vals ...FormattedText)
SetRow sets the contents of an entire row in this table
func (*FormattedTable) Sort ¶ added in v1.0.7
func (p *FormattedTable) Sort(start uint, sorter TableSorter)
Sort the data in this table according to a given table sorted.
type FormattedText ¶
type FormattedText struct {
// contains filtered or unexported fields
}
FormattedText represents, as the name suggests, a chunk of formatted text.
func NewColouredText ¶
func NewColouredText(text string, colour uint) FormattedText
NewColouredText constructs a new (coloured) chunk of text.
func NewFormattedText ¶
func NewFormattedText(text string, format AnsiEscape) FormattedText
NewFormattedText constructs a new chunk of text with a given format.
func NewText ¶
func NewText(text string) FormattedText
NewText constructs a new (unformatted) chunk of text.
func (*FormattedText) Bytes ¶
func (p *FormattedText) Bytes() []byte
Bytes returns an ANSI-formatted byte representing of this chunk.
func (*FormattedText) ClearFormat ¶
func (p *FormattedText) ClearFormat()
ClearFormat clears any formatting for this chunk of text.
func (*FormattedText) Clip ¶
func (p *FormattedText) Clip(start uint, end uint) FormattedText
Clip removes text from the start and end.
func (*FormattedText) Format ¶
func (p *FormattedText) Format(format AnsiEscape)
Format sets the format for this chunk of text.
func (*FormattedText) Len ¶
func (p *FormattedText) Len() uint
Len returns the number of characters [runes] in this chunk of formatted text. Observe that this does not include characters arising from the formatting escapes.
func (*FormattedText) Pad ¶ added in v1.0.7
func (p *FormattedText) Pad(width uint) FormattedText
Pad ensures the text is at least a given width, by prepending spaces.
type TableSorter ¶ added in v1.0.7
type TableSorter func([]FormattedText, []FormattedText) int
TableSorter represents a mechanism for sorting tables in some way.
func NewTableSorter ¶ added in v1.0.7
func NewTableSorter() TableSorter
NewTableSorter constructs a new table sorter which actually does nothing. The goal is then to further refine this as necessary.
func (TableSorter) Invert ¶ added in v1.1.21
func (p TableSorter) Invert() TableSorter
Invert the direction of sorting, so that largest values comes first.
func (TableSorter) SortColumn ¶ added in v1.0.7
func (p TableSorter) SortColumn(col uint) TableSorter
SortColumn adds a sort by the given column to the table sorter.
func (TableSorter) SortNumericalColumn ¶ added in v1.0.7
func (p TableSorter) SortNumericalColumn(col uint) TableSorter
SortNumericalColumn adds a sort by the given column to the table sorter.
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
Terminal provides a simple top-level window.
func (*Terminal) Add ¶
Add a new widget to this window. Widgets will be laid out vertically in the order they are added.
type Widget ¶
type Widget interface {
// Get height of this widget, where MaxUint indicates widget expands to take
// as much as it can.
GetHeight() uint
// Render this widget on the given canvas.
Render(canvas Canvas)
}
Widget is an abstract entity which can be displayed upon a terminal window.
type Window ¶
type Window interface {
// Add a new widget to this window. Widgets will be laid out vertically in
// the order they are added.
Add(w Widget)
// Render this window to the terminal.
Render() error
}
Window provides an abstraction over an interactive terminal session. This is fairly simplistic at this stage, and supports layout of widges in a vertical direction only.