Socket
Socket
Sign inDemoInstall

github.com/isbm/crtview

Package Overview
Dependencies
7
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/isbm/crtview

Package crtview implements rich widgets for terminal based user interfaces. See the demos folder and the example application provided with the NewApplication documentation for usage examples. This package is built on top of tcell, which provides the types necessary to create a terminal-based application (e.g. EventKey). For information on inherited types see the tcell documentation. tcell: https://github.com/gdamore/tcell Widgets must implement the Primitive interface. All widgets embed the base primitive, Box, and thus inherit its functions. This isn't necessarily required, but it makes more sense than reimplementing Box's functionality in each widget. The following widgets are available: Widgets may be used without an application created via NewApplication, allowing them to be integrated into any tcell-based application. All functions may be called concurrently (they are thread-safe). When called from multiple threads, functions will block until the application or widget becomes available. Function calls may be queued with Application.QueueUpdate to avoid blocking. This package supports unicode characters including wide characters. Widgets use keyboard shortcuts (a.k.a. keybindings) such as arrow keys and H/J/K/L by default. You may replace these defaults by modifying the shortcuts listed in Keys. You may also override keyboard shortcuts globally by setting a handler with Application.SetInputCapture. cbind is a library which simplifies the process of adding support for custom keyboard shortcuts to your application. It allows setting handlers for EventKeys. It also translates between EventKeys and human-readable strings such as "Alt+Enter". This makes it possible to store keybindings in a configuration file. cbind: https://gitlab.com/tslocum/cbind Bracketed paste mode is enabled by default. It may be disabled by calling Application.EnableBracketedPaste before Application.Run. The following demo shows how to handle paste events and process pasted text. tcell bracketed paste demo: https://github.com/gdamore/tcell/blob/master/_demos/mouse.go Mouse support may be enabled by calling Application.EnableMouse before Application.Run. See the example application provided with the Application.EnableMouse documentation. Double clicks are treated single clicks by default. Specify a maximum duration between clicks with Application.SetDoubleClickInterval to enable double clicks. A standard duration is provided as StandardDoubleClick. Mouse events are passed to: - The handler set with SetMouseCapture, which is reserved for use by application developers to permanently intercept mouse events. Return nil to stop propagation. - The MouseHandler method of the topmost widget under the mouse. Throughout this package, colors are specified using the tcell.Color type. Functions such as tcell.GetColor(), tcell.NewHexColor(), and tcell.NewRGBColor() can be used to create colors from W3C color names or RGB values. Almost all strings which are displayed can contain color tags. Color tags are W3C color names or six hexadecimal digits following a hash tag, wrapped in square brackets. Examples: A color tag changes the color of the characters following that color tag. This applies to almost everything from box titles, list text, form item labels, to table cells. In a TextView, this functionality must be explicitly enabled. See the TextView documentation for more information. Color tags may contain not just the foreground (text) color but also the background color and additional flags. In fact, the full definition of a color tag is as follows: Each of the three fields can be left blank and trailing fields can be omitted. (Empty square brackets "[]", however, are not considered color tags.) Colors that are not specified will be left unchanged. A field with just a dash ("-") means "reset to default". You can specify the following flags (some flags may not be supported by your terminal): Examples: In the rare event that you want to display a string such as "[red]" or "[#00ff1a]" without applying its effect, you need to put an opening square bracket before the closing square bracket. Note that the text inside the brackets will be matched less strictly than region or colors tags. I.e. any character that may be used in color or region tags will be recognized. Examples: You can use the Escape() function to insert brackets automatically where needed. Setting the background color of a primitive to tcell.ColorDefault will use the default terminal background color. To enable transparency (allowing one or more primitives to display behind a primitive) call SetBackgroundTransparent. When primitives are instantiated, they are initialized with colors taken from the global Styles variable. You may change this variable to adapt the look and feel of the primitives to your preferred style. Scroll bars are supported by the following widgets: List, Table, TextView and TreeView. Each widget will display scroll bars automatically when there are additional items offscreen, except TextView. See Widget.SetScrollBarColor and Widget.SetScrollBarVisibility. The following is an example application which shows a box titled "Greetings" containing the text "Hello, world!": First, we create a TextView with a border and a title. Then we create an application, set the TextView as its root primitive, and run the event loop. The application exits when the application's Stop() function is called or when Ctrl-C is pressed. If we have a primitive which consumes key presses, we call the application's SetFocus() function to redirect all key presses to that primitive. Most primitives then offer ways to install handlers that allow you to react to any actions performed on them. The "demos" subdirectory contains a demo for each widget, as well as a presentation which gives an overview of the widgets and how they may be used.


Version published

Readme

Source

crtview - Terminal-based user interface toolkit

This project is a fork of cview, which is also fork of original tview. :-) See docs/about-crtview.md for more details.

Features

Available widgets:

  • Input forms (including input/password fields, drop-down selections, checkboxes, and buttons)
  • Navigable multi-color text views
  • Selectable lists with context menus
  • Modal dialogs
  • Horizontal and vertical progress bars
  • Grid, Flexbox and tabbed panel layouts
  • Sophisticated navigable table views
  • Flexible tree views
  • Draggable and resizable windows
  • An application wrapper

Widgets may be customized and extended to suit any application.

Installation

go get github.com/isbm/crtview

Hello World

This basic example creates a TextView titled "Hello, World!" and displays it in your terminal:

package main

import (
	"github.com/isbm/crtview"
)

func main() {
	app := crtview.NewApplication()
	
	box := crtview.NewTextView()
		.SetBorder(true)
		.SetTitle("Hello, world!")
		.SetText("Here is some meaning-less text for your app.")
	
	app.SetRoot(box, true)
	if err := app.Run(); err != nil {
		panic(err)
	}
}

FAQs

Last updated on 26 Jan 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc