forked from tslocum/cview
Fork tview as cview
See FORK.md for details
This commit is contained in:
parent
1ee8d9874d
commit
b61132eddf
70 changed files with 472 additions and 506 deletions
14
.builds/amd64_freebsd.yml
Normal file
14
.builds/amd64_freebsd.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
arch: amd64
|
||||
environment:
|
||||
PROJECT_NAME: 'cview'
|
||||
CGO_ENABLED: '1'
|
||||
GO111MODULE: 'on'
|
||||
image: freebsd/latest
|
||||
packages:
|
||||
- go
|
||||
sources:
|
||||
- https://git.sr.ht/~tslocum/cview
|
||||
tasks:
|
||||
- test: |
|
||||
cd $PROJECT_NAME
|
||||
go test ./...
|
14
.builds/amd64_linux_alpine.yml
Normal file
14
.builds/amd64_linux_alpine.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
arch: x86_64
|
||||
environment:
|
||||
PROJECT_NAME: 'cview'
|
||||
CGO_ENABLED: '1'
|
||||
GO111MODULE: 'on'
|
||||
image: alpine/edge
|
||||
packages:
|
||||
- go
|
||||
sources:
|
||||
- https://git.sr.ht/~tslocum/cview
|
||||
tasks:
|
||||
- test: |
|
||||
cd $PROJECT_NAME
|
||||
go test ./...
|
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
.idea/
|
||||
dist/
|
||||
*.sh
|
||||
vendor/
|
|
@ -1,73 +0,0 @@
|
|||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
education, socio-economic status, nationality, personal appearance, race,
|
||||
religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at https://rentafounder.com/page/about-me/. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
|
@ -1,35 +1,19 @@
|
|||
# Contributing to tview
|
||||
This document assists cview users and developers with sharing issues,
|
||||
suggestions and patches.
|
||||
|
||||
First of all, thank you for taking the time to contribute.
|
||||
# Issues and suggestions
|
||||
|
||||
The following provides you with some guidance on how to contribute to this project. Mainly, it is meant to save us all some time so please read it, it's not long.
|
||||
Please include as much relevant information as possible.
|
||||
|
||||
Please note that this document is work in progress so I might add to it in the future.
|
||||
Review project [documentation](https://godoc.org/git.sr.ht/~tslocum/cview)
|
||||
before submitting an issue.
|
||||
|
||||
## Issues
|
||||
Share issues and suggestions on the [issue tracker](https://todo.sr.ht/~tslocum/cview).
|
||||
|
||||
- Please include enough information so everybody understands your request.
|
||||
- Screenshots or code that illustrates your point always helps.
|
||||
- It's fine to ask for help. But you should have checked out the [documentation](https://godoc.org/github.com/rivo/tview) first in any case.
|
||||
- If you request a new feature, state your motivation and share a use case that you faced where you needed that new feature. It should be something that others will also need.
|
||||
# Patches (pull requests)
|
||||
|
||||
## Pull Requests
|
||||
Send patches to the [cview-dev](https://lists.sr.ht/~tslocum/cview-dev) mailing
|
||||
list.
|
||||
|
||||
In my limited time I can spend on this project, I will always go through issues first before looking at pull requests. It takes a _lot_ of time to look at code that you submitted and I may not have that time. So be prepared to have your pull requests lying around for a long time.
|
||||
|
||||
Therefore, if you have a feature request, open an issue first before sending me a pull request, and allow for some discussion. It may save you from writing code that will get rejected. If your case is strong, there is a good chance that I will add the feature for you.
|
||||
|
||||
I'm very picky about the code that goes into this repo. So if you violate any of the following guidelines, there is a good chance I won't merge your pull request.
|
||||
|
||||
- There must be a strong case for your additions/changes, such as:
|
||||
- Bug fixes
|
||||
- Features that are needed (see "Issues" above; state your motivation)
|
||||
- Improvements in stability or performance (if readability does not suffer)
|
||||
- Your code must follow the structure of the existing code. Don't just patch something on. Try to understand how `tview` is currently designed and follow that design. Your code needs to be consistent with existing code.
|
||||
- If you're adding code that increases the work required to maintain the project, you must be willing to take responsibility for that extra work. I will ask you to maintain your part of the code in the long run.
|
||||
- Function/type/variable/constant names must be as descriptive as they are right now. Follow the conventions of the package.
|
||||
- All functions/types/variables/constants, even private ones, must have comments in good English. These comments must be elaborate enough so that new users of the package understand them and can follow them. Provide examples if you have to. Start all sentences upper-case, as is common in English, and end them with a period.
|
||||
- A new function should be located close to related functions in the file. For example, `GetColor()` should come after (or before) `SetColor()`.
|
||||
- Your changes must not decrease the project's [Go Report](https://goreportcard.com/report/github.com/rivo/tview) rating.
|
||||
- No breaking changes unless there is absolutely no other way.
|
||||
- If an issue accompanies your pull request, reference it in the PR's comments, e.g. "Fixes #123", so it is closed automatically when the PR is closed.
|
||||
See [git-send-email.io](https://git-send-email.io) for information on sending
|
||||
patches via email.
|
||||
|
|
28
FORK.md
Normal file
28
FORK.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
This document explains why [tview](https://github.com/rivo/tview) was forked to
|
||||
create [cview](https://git.sr.ht/~tslocum/cview). It also tracks which
|
||||
tview pull requests have been merged into cview.
|
||||
|
||||
# Why fork?
|
||||
|
||||
[rivo](https://github.com/rivo), the creator and sole maintainer of tview,
|
||||
explains his reviewing and merging process in a [a GitHub comment](https://github.com/rivo/tview/pull/298#issuecomment-559373851).
|
||||
|
||||
He states that he does not have the necessary time or interest to review,
|
||||
discuss and merge pull requests:
|
||||
|
||||
>this project is quite low in priority. It doesn't generate any income for me
|
||||
>and, unfortunately, reviewing issues and PRs is also not much "fun".
|
||||
|
||||
>But some other people submitted large PRs which will cost me many hours to
|
||||
>review. (I had to chuckle a bit when I saw [this comment](https://github.com/rivo/tview/pull/363#issuecomment-555484734).)
|
||||
|
||||
>Lastly, I'm the one who ends up maintaining this code. I have to be 100%
|
||||
>behind it, understand it 100%, and be able to make changes to it later if
|
||||
> necessary.
|
||||
|
||||
cview aims to solve these issues by increasing the number of project
|
||||
maintainers and allowing code changes which may be outside of tview's scope.
|
||||
|
||||
# Merged pull requests
|
||||
|
||||
*Coming soon*
|
59
LICENSE
Normal file
59
LICENSE
Normal file
|
@ -0,0 +1,59 @@
|
|||
cview forked tview at the following commit:
|
||||
|
||||
1ee8d9874dcfca377e638a1572ef3718f416ee0d
|
||||
Sun Dec 29 17:56:09 2019 +0100
|
||||
Merge pull request #292 from mikeschinkel/box_gettitle
|
||||
|
||||
The tview license applies to the above commit and all prior commits.
|
||||
|
||||
----------
|
||||
|
||||
cview license:
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Trevor Slocum <trevor@rocketnine.space>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
----------
|
||||
|
||||
tview license:
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Oliver Kuederle
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
21
LICENSE.txt
21
LICENSE.txt
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2018 Oliver Kuederle
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
90
README.md
90
README.md
|
@ -1,15 +1,15 @@
|
|||
# Rich Interactive Widgets for Terminal UIs
|
||||
# Terminal-based user interface toolkit
|
||||
[![GoDoc](https://godoc.org/git.sr.ht/~tslocum/cview?status.svg)](https://godoc.org/git.sr.ht/~tslocum/cview)
|
||||
[![builds.sr.ht status](https://builds.sr.ht/~tslocum/cview.svg)](https://builds.sr.ht/~tslocum/cview)
|
||||
|
||||
[![Godoc Reference](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/rivo/tview)
|
||||
[![Go Report](https://img.shields.io/badge/go%20report-A%2B-brightgreen.svg)](https://goreportcard.com/report/github.com/rivo/tview)
|
||||
This package is a [fork](https://man.sr.ht/~tslocum/cview/FORK.md) of [tview](https://github.com/rivo/tview).
|
||||
It allows the creation of rich terminal-based user interfaces.
|
||||
|
||||
This Go package provides commonly needed components for terminal based user interfaces.
|
||||
![Screenshot](https://git.sr.ht/~tslocum/cview/blob/master/cview.gif)
|
||||
|
||||
![Screenshot](tview.gif)
|
||||
Available widgets:
|
||||
|
||||
Among these components are:
|
||||
|
||||
- __Input forms__ (include __input/password fields__, __drop-down selections__, __checkboxes__, and __buttons__)
|
||||
- __Input forms__ (including __input/password fields__, __drop-down selections__, __checkboxes__, and __buttons__)
|
||||
- Navigable multi-color __text views__
|
||||
- Sophisticated navigable __table views__
|
||||
- Flexible __tree views__
|
||||
|
@ -18,12 +18,12 @@ Among these components are:
|
|||
- Modal __message windows__
|
||||
- An __application__ wrapper
|
||||
|
||||
They come with lots of customization options and can be easily extended to fit your needs.
|
||||
Widgets may be customized and extended to suit any application.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
go get github.com/rivo/tview
|
||||
go get git.sr.ht/~tslocum/cview@latest
|
||||
```
|
||||
|
||||
## Hello World
|
||||
|
@ -34,77 +34,37 @@ This basic example creates a box titled "Hello, World!" and displays it in your
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
func main() {
|
||||
box := tview.NewBox().SetBorder(true).SetTitle("Hello, world!")
|
||||
if err := tview.NewApplication().SetRoot(box, true).Run(); err != nil {
|
||||
box := cview.NewBox().SetBorder(true).SetTitle("Hello, world!")
|
||||
if err := cview.NewApplication().SetRoot(box, true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Check out the [GitHub Wiki](https://github.com/rivo/tview/wiki) for more examples along with screenshots. Or try the examples in the "demos" subdirectory.
|
||||
Examples are available in the "demos" subdirectory.
|
||||
|
||||
For a presentation highlighting this package, compile and run the program found in the "demos/presentation" subdirectory.
|
||||
For a presentation highlighting the features of this package, compile and run
|
||||
the program in the "demos/presentation" subdirectory.
|
||||
|
||||
## Documentation
|
||||
|
||||
Refer to https://godoc.org/github.com/rivo/tview for the package's documentation.
|
||||
Package documentation is available on [godoc](https://godoc.org/git.sr.ht/~tslocum/cview).
|
||||
|
||||
## Dependencies
|
||||
|
||||
This package is based on [github.com/gdamore/tcell](https://github.com/gdamore/tcell) (and its dependencies) as well as on [github.com/rivo/uniseg](https://github.com/rivo/uniseg).
|
||||
This package is based on [github.com/gdamore/tcell](https://github.com/gdamore/tcell)
|
||||
(and its dependencies) and [github.com/rivo/uniseg](https://github.com/rivo/uniseg).
|
||||
|
||||
## Your Feedback
|
||||
## Support
|
||||
|
||||
Add your issue here on GitHub. Feel free to get in touch if you have any questions.
|
||||
[CONTRIBUTING.md](https://man.sr.ht/~tslocum/cview/CONTRIBUTING.md) describes how to share
|
||||
issues, suggestions and patches (pull requests).
|
||||
|
||||
## Version History
|
||||
cview has two mailing lists:
|
||||
|
||||
(There are no corresponding tags in the project. I only keep such a history in this README.)
|
||||
|
||||
- v0.20 (2019-07-08)
|
||||
- Added autocomplete functionality to `InputField`.
|
||||
- v0.19 (2018-10-28)
|
||||
- Added `QueueUpdate()` and `QueueEvent()` to `Application` to help with modifications to primitives from goroutines.
|
||||
- v0.18 (2018-10-18)
|
||||
- `InputField` elements can now be navigated freely.
|
||||
- v0.17 (2018-06-20)
|
||||
- Added `TreeView`.
|
||||
- v0.15 (2018-05-02)
|
||||
- `Flex` and `Grid` don't clear their background per default, thus allowing for custom modals. See the [Wiki](https://github.com/rivo/tview/wiki/Modal) for an example.
|
||||
- v0.14 (2018-04-13)
|
||||
- Added an `Escape()` function which keep strings like color or region tags from being recognized as such.
|
||||
- Added `ANSIWriter()` and `TranslateANSI()` which convert ANSI escape sequences to `tview` color tags.
|
||||
- v0.13 (2018-04-01)
|
||||
- Added background colors and text attributes to color tags.
|
||||
- v0.12 (2018-03-13)
|
||||
- Added "suspended mode" to `Application`.
|
||||
- v0.11 (2018-03-02)
|
||||
- Added a `RemoveItem()` function to `Grid` and `Flex`.
|
||||
- v0.10 (2018-02-22)
|
||||
- Direct access to the `screen` object through callback in `Box` (i.e. for all primitives).
|
||||
- v0.9 (2018-02-20)
|
||||
- Introduced `Grid` layout.
|
||||
- Direct access to the `screen` object through callbacks in `Application`.
|
||||
- v0.8 (2018-01-17)
|
||||
- Color tags can now be used almost everywhere.
|
||||
- v0.7 (2018-01-16)
|
||||
- Forms can now also have a horizontal layout.
|
||||
- v0.6 (2018-01-14)
|
||||
- All primitives can now intercept all key events when they have focus.
|
||||
- Key events can also be intercepted globally (changed to a more general, consistent handling)
|
||||
- v0.5 (2018-01-13)
|
||||
- `TextView` now has word wrapping and text alignment
|
||||
- v0.4 (2018-01-12)
|
||||
- `TextView` now accepts color tags with any W3C color (including RGB hex values).
|
||||
- Support for wide unicode characters.
|
||||
- v0.3 (2018-01-11)
|
||||
- Added masking to `InputField` and password entry to `Form`.
|
||||
- v0.2 (2018-01-10)
|
||||
- Added `Styles` variable with default colors for primitives.
|
||||
- Completed some missing InputField functions.
|
||||
- v0.1 (2018-01-06)
|
||||
- First Release.
|
||||
- [cview-discuss](https://lists.sr.ht/~tslocum/cview-discuss) for general discussion
|
||||
- [cview-dev](https://lists.sr.ht/~tslocum/cview-dev) for development discussion
|
||||
|
|
8
ansi.go
8
ansi.go
|
@ -1,4 +1,4 @@
|
|||
package tview
|
||||
package cview
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -16,7 +16,7 @@ const (
|
|||
ansiControlSequence
|
||||
)
|
||||
|
||||
// ansi is a io.Writer which translates ANSI escape codes into tview color
|
||||
// ansi is a io.Writer which translates ANSI escape codes into cview color
|
||||
// tags.
|
||||
type ansi struct {
|
||||
io.Writer
|
||||
|
@ -30,7 +30,7 @@ type ansi struct {
|
|||
}
|
||||
|
||||
// ANSIWriter returns an io.Writer which translates any ANSI escape codes
|
||||
// written to it into tview color tags. Other escape codes don't have an effect
|
||||
// written to it into cview color tags. Other escape codes don't have an effect
|
||||
// and are simply removed. The translated text is written to the provided
|
||||
// writer.
|
||||
func ANSIWriter(writer io.Writer) io.Writer {
|
||||
|
@ -230,7 +230,7 @@ func (a *ansi) Write(text []byte) (int, error) {
|
|||
}
|
||||
|
||||
// TranslateANSI replaces ANSI escape sequences found in the provided string
|
||||
// with tview's color tags and returns the resulting string.
|
||||
// with cview's color tags and returns the resulting string.
|
||||
func TranslateANSI(text string) string {
|
||||
var buffer bytes.Buffer
|
||||
writer := ANSIWriter(&buffer)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package tview
|
||||
package cview
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
@ -18,7 +18,7 @@ const queueSize = 100
|
|||
// The following command displays a primitive p on the screen until Ctrl-C is
|
||||
// pressed:
|
||||
//
|
||||
// if err := tview.NewApplication().SetRoot(p, true).Run(); err != nil {
|
||||
// if err := cview.NewApplication().SetRoot(p, true).Run(); err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
type Application struct {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package tview
|
||||
package cview
|
||||
|
||||
// Borders defines various borders used when primitives are drawn.
|
||||
// These may be changed to accommodate a different look and feel.
|
||||
|
|
4
box.go
4
box.go
|
@ -1,4 +1,4 @@
|
|||
package tview
|
||||
package cview
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
|
@ -11,7 +11,7 @@ import (
|
|||
// Note that all classes which subclass from Box will also have access to its
|
||||
// functions.
|
||||
//
|
||||
// See https://github.com/rivo/tview/wiki/Box for an example.
|
||||
// See https://git.sr.ht/~tslocum/cview/wiki/Box for an example.
|
||||
type Box struct {
|
||||
// The position of the rect.
|
||||
x, y, width, height int
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package tview
|
||||
package cview
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
// Button is labeled box that triggers an action when selected.
|
||||
//
|
||||
// See https://github.com/rivo/tview/wiki/Button for an example.
|
||||
// See https://git.sr.ht/~tslocum/cview/wiki/Button for an example.
|
||||
type Button struct {
|
||||
*Box
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package tview
|
||||
package cview
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
|
@ -7,7 +7,7 @@ import (
|
|||
// Checkbox implements a simple box for boolean values which can be checked and
|
||||
// unchecked.
|
||||
//
|
||||
// See https://github.com/rivo/tview/wiki/Checkbox for an example.
|
||||
// See https://git.sr.ht/~tslocum/cview/wiki/Checkbox for an example.
|
||||
type Checkbox struct {
|
||||
*Box
|
||||
|
||||
|
|
Before Width: | Height: | Size: 2.1 MiB After Width: | Height: | Size: 2.1 MiB |
|
@ -3,15 +3,15 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
func main() {
|
||||
box := tview.NewBox().
|
||||
box := cview.NewBox().
|
||||
SetBorder(true).
|
||||
SetBorderAttributes(tcell.AttrBold).
|
||||
SetTitle("A [red]c[yellow]o[green]l[darkcyan]o[blue]r[darkmagenta]f[red]u[yellow]l[white] [black:red]c[:yellow]o[:green]l[:darkcyan]o[:blue]r[:darkmagenta]f[:red]u[:yellow]l[white:] [::bu]title")
|
||||
if err := tview.NewApplication().SetRoot(box, true).Run(); err != nil {
|
||||
if err := cview.NewApplication().SetRoot(box, true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// Demo code for the Button primitive.
|
||||
package main
|
||||
|
||||
import "github.com/rivo/tview"
|
||||
import "git.sr.ht/~tslocum/cview"
|
||||
|
||||
func main() {
|
||||
app := tview.NewApplication()
|
||||
button := tview.NewButton("Hit Enter to close").SetSelectedFunc(func() {
|
||||
app := cview.NewApplication()
|
||||
button := cview.NewButton("Hit Enter to close").SetSelectedFunc(func() {
|
||||
app.Stop()
|
||||
})
|
||||
button.SetBorder(true).SetRect(0, 0, 22, 3)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// Demo code for the Checkbox primitive.
|
||||
package main
|
||||
|
||||
import "github.com/rivo/tview"
|
||||
import "git.sr.ht/~tslocum/cview"
|
||||
|
||||
func main() {
|
||||
app := tview.NewApplication()
|
||||
checkbox := tview.NewCheckbox().SetLabel("Hit Enter to check box: ")
|
||||
app := cview.NewApplication()
|
||||
checkbox := cview.NewCheckbox().SetLabel("Hit Enter to check box: ")
|
||||
if err := app.SetRoot(checkbox, true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// Demo code for the DropDown primitive.
|
||||
package main
|
||||
|
||||
import "github.com/rivo/tview"
|
||||
import "git.sr.ht/~tslocum/cview"
|
||||
|
||||
func main() {
|
||||
app := tview.NewApplication()
|
||||
dropdown := tview.NewDropDown().
|
||||
app := cview.NewApplication()
|
||||
dropdown := cview.NewDropDown().
|
||||
SetLabel("Select an option (hit Enter): ").
|
||||
SetOptions([]string{"First", "Second", "Third", "Fourth", "Fifth"}, nil)
|
||||
if err := app.SetRoot(dropdown, true).Run(); err != nil {
|
||||
|
|
|
@ -2,18 +2,18 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := tview.NewApplication()
|
||||
flex := tview.NewFlex().
|
||||
AddItem(tview.NewBox().SetBorder(true).SetTitle("Left (1/2 x width of Top)"), 0, 1, false).
|
||||
AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
|
||||
AddItem(tview.NewBox().SetBorder(true).SetTitle("Top"), 0, 1, false).
|
||||
AddItem(tview.NewBox().SetBorder(true).SetTitle("Middle (3 x height of Top)"), 0, 3, false).
|
||||
AddItem(tview.NewBox().SetBorder(true).SetTitle("Bottom (5 rows)"), 5, 1, false), 0, 2, false).
|
||||
AddItem(tview.NewBox().SetBorder(true).SetTitle("Right (20 cols)"), 20, 1, false)
|
||||
app := cview.NewApplication()
|
||||
flex := cview.NewFlex().
|
||||
AddItem(cview.NewBox().SetBorder(true).SetTitle("Left (1/2 x width of Top)"), 0, 1, false).
|
||||
AddItem(cview.NewFlex().SetDirection(cview.FlexRow).
|
||||
AddItem(cview.NewBox().SetBorder(true).SetTitle("Top"), 0, 1, false).
|
||||
AddItem(cview.NewBox().SetBorder(true).SetTitle("Middle (3 x height of Top)"), 0, 3, false).
|
||||
AddItem(cview.NewBox().SetBorder(true).SetTitle("Bottom (5 rows)"), 5, 1, false), 0, 2, false).
|
||||
AddItem(cview.NewBox().SetBorder(true).SetTitle("Right (20 cols)"), 20, 1, false)
|
||||
if err := app.SetRoot(flex, true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := tview.NewApplication()
|
||||
form := tview.NewForm().
|
||||
app := cview.NewApplication()
|
||||
form := cview.NewForm().
|
||||
AddDropDown("Title", []string{"Mr.", "Ms.", "Mrs.", "Dr.", "Prof."}, 0, nil).
|
||||
AddInputField("First name", "", 20, nil, nil).
|
||||
AddInputField("Last name", "", 20, nil, nil).
|
||||
|
@ -17,7 +17,7 @@ func main() {
|
|||
AddButton("Quit", func() {
|
||||
app.Stop()
|
||||
})
|
||||
form.SetBorder(true).SetTitle("Enter some data").SetTitleAlign(tview.AlignLeft)
|
||||
form.SetBorder(true).SetTitle("Enter some data").SetTitleAlign(cview.AlignLeft)
|
||||
if err := app.SetRoot(form, true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -3,19 +3,19 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := tview.NewApplication()
|
||||
frame := tview.NewFrame(tview.NewBox().SetBackgroundColor(tcell.ColorBlue)).
|
||||
app := cview.NewApplication()
|
||||
frame := cview.NewFrame(cview.NewBox().SetBackgroundColor(tcell.ColorBlue)).
|
||||
SetBorders(2, 2, 2, 2, 4, 4).
|
||||
AddText("Header left", true, tview.AlignLeft, tcell.ColorWhite).
|
||||
AddText("Header middle", true, tview.AlignCenter, tcell.ColorWhite).
|
||||
AddText("Header right", true, tview.AlignRight, tcell.ColorWhite).
|
||||
AddText("Header second middle", true, tview.AlignCenter, tcell.ColorRed).
|
||||
AddText("Footer middle", false, tview.AlignCenter, tcell.ColorGreen).
|
||||
AddText("Footer second middle", false, tview.AlignCenter, tcell.ColorGreen)
|
||||
AddText("Header left", true, cview.AlignLeft, tcell.ColorWhite).
|
||||
AddText("Header middle", true, cview.AlignCenter, tcell.ColorWhite).
|
||||
AddText("Header right", true, cview.AlignRight, tcell.ColorWhite).
|
||||
AddText("Header second middle", true, cview.AlignCenter, tcell.ColorRed).
|
||||
AddText("Footer middle", false, cview.AlignCenter, tcell.ColorGreen).
|
||||
AddText("Footer second middle", false, cview.AlignCenter, tcell.ColorGreen)
|
||||
if err := app.SetRoot(frame, true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -2,20 +2,20 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
func main() {
|
||||
newPrimitive := func(text string) tview.Primitive {
|
||||
return tview.NewTextView().
|
||||
SetTextAlign(tview.AlignCenter).
|
||||
newPrimitive := func(text string) cview.Primitive {
|
||||
return cview.NewTextView().
|
||||
SetTextAlign(cview.AlignCenter).
|
||||
SetText(text)
|
||||
}
|
||||
menu := newPrimitive("Menu")
|
||||
main := newPrimitive("Main content")
|
||||
sideBar := newPrimitive("Side Bar")
|
||||
|
||||
grid := tview.NewGrid().
|
||||
grid := cview.NewGrid().
|
||||
SetRows(3, 0, 3).
|
||||
SetColumns(30, 0, 30).
|
||||
SetBorders(true).
|
||||
|
@ -32,7 +32,7 @@ func main() {
|
|||
AddItem(main, 1, 1, 1, 1, 0, 100, false).
|
||||
AddItem(sideBar, 1, 2, 1, 1, 0, 100, false)
|
||||
|
||||
if err := tview.NewApplication().SetRoot(grid, true).Run(); err != nil {
|
||||
if err := cview.NewApplication().SetRoot(grid, true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
// 1,000 most common English words.
|
||||
|
@ -12,8 +12,8 @@ const wordList = "ability,able,about,above,accept,according,account,across,act,a
|
|||
|
||||
func main() {
|
||||
words := strings.Split(wordList, ",")
|
||||
app := tview.NewApplication()
|
||||
inputField := tview.NewInputField().
|
||||
app := cview.NewApplication()
|
||||
inputField := cview.NewInputField().
|
||||
SetLabel("Enter a word: ").
|
||||
SetFieldWidth(30).
|
||||
SetDoneFunc(func(key tcell.Key) {
|
|
@ -8,7 +8,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
type company struct {
|
||||
|
@ -16,8 +16,8 @@ type company struct {
|
|||
}
|
||||
|
||||
func main() {
|
||||
app := tview.NewApplication()
|
||||
inputField := tview.NewInputField().
|
||||
app := cview.NewApplication()
|
||||
inputField := cview.NewInputField().
|
||||
SetLabel("Enter a company name: ").
|
||||
SetFieldWidth(30).
|
||||
SetDoneFunc(func(key tcell.Key) {
|
|
@ -3,16 +3,16 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := tview.NewApplication()
|
||||
inputField := tview.NewInputField().
|
||||
app := cview.NewApplication()
|
||||
inputField := cview.NewInputField().
|
||||
SetLabel("Enter a number: ").
|
||||
SetPlaceholder("E.g. 1234").
|
||||
SetFieldWidth(10).
|
||||
SetAcceptanceFunc(tview.InputFieldInteger).
|
||||
SetAcceptanceFunc(cview.InputFieldInteger).
|
||||
SetDoneFunc(func(key tcell.Key) {
|
||||
app.Stop()
|
||||
})
|
|
@ -2,12 +2,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := tview.NewApplication()
|
||||
list := tview.NewList().
|
||||
app := cview.NewApplication()
|
||||
list := cview.NewList().
|
||||
AddItem("List item 1", "Some explanatory text", 'a', nil).
|
||||
AddItem("List item 2", "Some explanatory text", 'b', nil).
|
||||
AddItem("List item 3", "Some explanatory text", 'c', nil).
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := tview.NewApplication()
|
||||
modal := tview.NewModal().
|
||||
app := cview.NewApplication()
|
||||
modal := cview.NewModal().
|
||||
SetText("Do you want to quit the application?").
|
||||
AddButtons([]string{"Quit", "Cancel"}).
|
||||
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
|
||||
|
|
|
@ -4,18 +4,18 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
const pageCount = 5
|
||||
|
||||
func main() {
|
||||
app := tview.NewApplication()
|
||||
pages := tview.NewPages()
|
||||
app := cview.NewApplication()
|
||||
pages := cview.NewPages()
|
||||
for page := 0; page < pageCount; page++ {
|
||||
func(page int) {
|
||||
pages.AddPage(fmt.Sprintf("page-%d", page),
|
||||
tview.NewModal().
|
||||
cview.NewModal().
|
||||
SetText(fmt.Sprintf("This is page %d. Choose where to go next.", page+1)).
|
||||
AddButtons([]string{"Next", "Quit"}).
|
||||
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package main
|
||||
|
||||
import "github.com/rivo/tview"
|
||||
import "git.sr.ht/~tslocum/cview"
|
||||
|
||||
// Center returns a new primitive which shows the provided primitive in its
|
||||
// center, given the provided primitive's size.
|
||||
func Center(width, height int, p tview.Primitive) tview.Primitive {
|
||||
return tview.NewFlex().
|
||||
AddItem(tview.NewBox(), 0, 1, false).
|
||||
AddItem(tview.NewFlex().
|
||||
SetDirection(tview.FlexRow).
|
||||
AddItem(tview.NewBox(), 0, 1, false).
|
||||
func Center(width, height int, p cview.Primitive) cview.Primitive {
|
||||
return cview.NewFlex().
|
||||
AddItem(cview.NewBox(), 0, 1, false).
|
||||
AddItem(cview.NewFlex().
|
||||
SetDirection(cview.FlexRow).
|
||||
AddItem(cview.NewBox(), 0, 1, false).
|
||||
AddItem(p, height, 1, true).
|
||||
AddItem(tview.NewBox(), 0, 1, false), width, 1, true).
|
||||
AddItem(tview.NewBox(), 0, 1, false)
|
||||
AddItem(cview.NewBox(), 0, 1, false), width, 1, true).
|
||||
AddItem(cview.NewBox(), 0, 1, false)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
// The width of the code window.
|
||||
|
@ -11,15 +11,15 @@ const codeWidth = 56
|
|||
|
||||
// Code returns a primitive which displays the given primitive (with the given
|
||||
// size) on the left side and its source code on the right side.
|
||||
func Code(p tview.Primitive, width, height int, code string) tview.Primitive {
|
||||
func Code(p cview.Primitive, width, height int, code string) cview.Primitive {
|
||||
// Set up code view.
|
||||
codeView := tview.NewTextView().
|
||||
codeView := cview.NewTextView().
|
||||
SetWrap(false).
|
||||
SetDynamicColors(true)
|
||||
codeView.SetBorderPadding(1, 1, 2, 0)
|
||||
fmt.Fprint(codeView, code)
|
||||
|
||||
return tview.NewFlex().
|
||||
return cview.NewFlex().
|
||||
AddItem(Center(width, height, p), 0, 1, true).
|
||||
AddItem(codeView, codeWidth, 1, false)
|
||||
}
|
||||
|
|
|
@ -4,14 +4,14 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
const colorsText = `You can use color tags almost everywhere to partially change the color of a string. Simply put a color name or hex string in square brackets to change the following characters' color. H[green]er[white]e i[yellow]s a[darkcyan]n ex[red]amp[white]le. The [black:red]tags [black:green]look [black:yellow]like [::u]this: [blue:yellow:u[] [#00ff00[]`
|
||||
|
||||
// Colors demonstrates how to use colors.
|
||||
func Colors(nextSlide func()) (title string, content tview.Primitive) {
|
||||
table := tview.NewTable().
|
||||
func Colors(nextSlide func()) (title string, content cview.Primitive) {
|
||||
table := cview.NewTable().
|
||||
SetBorders(true).
|
||||
SetBordersColor(tcell.ColorBlue).
|
||||
SetDoneFunc(func(key tcell.Key) {
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
const logo = `
|
||||
|
@ -18,12 +18,12 @@ const logo = `
|
|||
`
|
||||
|
||||
const (
|
||||
subtitle = `tview - Rich Widgets for Terminal UIs`
|
||||
subtitle = `cview - Rich Widgets for Terminal UIs`
|
||||
navigation = `Ctrl-N: Next slide Ctrl-P: Previous slide Ctrl-C: Exit`
|
||||
)
|
||||
|
||||
// Cover returns the cover page.
|
||||
func Cover(nextSlide func()) (title string, content tview.Primitive) {
|
||||
func Cover(nextSlide func()) (title string, content cview.Primitive) {
|
||||
// What's the size of the logo?
|
||||
lines := strings.Split(logo, "\n")
|
||||
logoWidth := 0
|
||||
|
@ -33,7 +33,7 @@ func Cover(nextSlide func()) (title string, content tview.Primitive) {
|
|||
logoWidth = len(line)
|
||||
}
|
||||
}
|
||||
logoBox := tview.NewTextView().
|
||||
logoBox := cview.NewTextView().
|
||||
SetTextColor(tcell.ColorGreen).
|
||||
SetDoneFunc(func(key tcell.Key) {
|
||||
nextSlide()
|
||||
|
@ -41,20 +41,20 @@ func Cover(nextSlide func()) (title string, content tview.Primitive) {
|
|||
fmt.Fprint(logoBox, logo)
|
||||
|
||||
// Create a frame for the subtitle and navigation infos.
|
||||
frame := tview.NewFrame(tview.NewBox()).
|
||||
frame := cview.NewFrame(cview.NewBox()).
|
||||
SetBorders(0, 0, 0, 0, 0, 0).
|
||||
AddText(subtitle, true, tview.AlignCenter, tcell.ColorWhite).
|
||||
AddText("", true, tview.AlignCenter, tcell.ColorWhite).
|
||||
AddText(navigation, true, tview.AlignCenter, tcell.ColorDarkMagenta)
|
||||
AddText(subtitle, true, cview.AlignCenter, tcell.ColorWhite).
|
||||
AddText("", true, cview.AlignCenter, tcell.ColorWhite).
|
||||
AddText(navigation, true, cview.AlignCenter, tcell.ColorDarkMagenta)
|
||||
|
||||
// Create a Flex layout that centers the logo and subtitle.
|
||||
flex := tview.NewFlex().
|
||||
SetDirection(tview.FlexRow).
|
||||
AddItem(tview.NewBox(), 0, 7, false).
|
||||
AddItem(tview.NewFlex().
|
||||
AddItem(tview.NewBox(), 0, 1, false).
|
||||
flex := cview.NewFlex().
|
||||
SetDirection(cview.FlexRow).
|
||||
AddItem(cview.NewBox(), 0, 7, false).
|
||||
AddItem(cview.NewFlex().
|
||||
AddItem(cview.NewBox(), 0, 1, false).
|
||||
AddItem(logoBox, logoWidth, 1, true).
|
||||
AddItem(tview.NewBox(), 0, 1, false), logoHeight, 1, true).
|
||||
AddItem(cview.NewBox(), 0, 1, false), logoHeight, 1, true).
|
||||
AddItem(frame, 0, 10, false)
|
||||
|
||||
return "Start", flex
|
||||
|
|
|
@ -4,15 +4,15 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
// End shows the final slide.
|
||||
func End(nextSlide func()) (title string, content tview.Primitive) {
|
||||
textView := tview.NewTextView().SetDoneFunc(func(key tcell.Key) {
|
||||
func End(nextSlide func()) (title string, content cview.Primitive) {
|
||||
textView := cview.NewTextView().SetDoneFunc(func(key tcell.Key) {
|
||||
nextSlide()
|
||||
})
|
||||
url := "https://github.com/rivo/tview"
|
||||
url := "https://git.sr.ht/~tslocum/cview"
|
||||
fmt.Fprint(textView, url)
|
||||
return "End", Center(len(url), 1, textView)
|
||||
}
|
||||
|
|
|
@ -2,14 +2,14 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
// Flex demonstrates flexbox layout.
|
||||
func Flex(nextSlide func()) (title string, content tview.Primitive) {
|
||||
func Flex(nextSlide func()) (title string, content cview.Primitive) {
|
||||
modalShown := false
|
||||
pages := tview.NewPages()
|
||||
textView := tview.NewTextView().
|
||||
pages := cview.NewPages()
|
||||
textView := cview.NewTextView().
|
||||
SetDoneFunc(func(key tcell.Key) {
|
||||
if modalShown {
|
||||
nextSlide()
|
||||
|
@ -20,15 +20,15 @@ func Flex(nextSlide func()) (title string, content tview.Primitive) {
|
|||
}
|
||||
})
|
||||
textView.SetBorder(true).SetTitle("Flexible width, twice of middle column")
|
||||
flex := tview.NewFlex().
|
||||
flex := cview.NewFlex().
|
||||
AddItem(textView, 0, 2, true).
|
||||
AddItem(tview.NewFlex().
|
||||
SetDirection(tview.FlexRow).
|
||||
AddItem(tview.NewBox().SetBorder(true).SetTitle("Flexible width"), 0, 1, false).
|
||||
AddItem(tview.NewBox().SetBorder(true).SetTitle("Fixed height"), 15, 1, false).
|
||||
AddItem(tview.NewBox().SetBorder(true).SetTitle("Flexible height"), 0, 1, false), 0, 1, false).
|
||||
AddItem(tview.NewBox().SetBorder(true).SetTitle("Fixed width"), 30, 1, false)
|
||||
modal := tview.NewModal().
|
||||
AddItem(cview.NewFlex().
|
||||
SetDirection(cview.FlexRow).
|
||||
AddItem(cview.NewBox().SetBorder(true).SetTitle("Flexible width"), 0, 1, false).
|
||||
AddItem(cview.NewBox().SetBorder(true).SetTitle("Fixed height"), 15, 1, false).
|
||||
AddItem(cview.NewBox().SetBorder(true).SetTitle("Flexible height"), 0, 1, false), 0, 1, false).
|
||||
AddItem(cview.NewBox().SetBorder(true).SetTitle("Fixed width"), 30, 1, false)
|
||||
modal := cview.NewModal().
|
||||
SetText("Resize the window to see the effect of the flexbox parameters").
|
||||
AddButtons([]string{"Ok"}).SetDoneFunc(func(buttonIndex int, buttonLabel string) {
|
||||
pages.HidePage("modal")
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
const form = `[green]package[white] main
|
||||
|
||||
[green]import[white] (
|
||||
[red]"github.com/rivo/tview"[white]
|
||||
[red]"git.sr.ht/~tslocum/cview"[white]
|
||||
)
|
||||
|
||||
[green]func[white] [yellow]main[white]() {
|
||||
form := tview.[yellow]NewForm[white]().
|
||||
form := cview.[yellow]NewForm[white]().
|
||||
[yellow]AddInputField[white]([red]"First name:"[white], [red]""[white], [red]20[white], nil, nil).
|
||||
[yellow]AddInputField[white]([red]"Last name:"[white], [red]""[white], [red]20[white], nil, nil).
|
||||
[yellow]AddDropDown[white]([red]"Role:"[white], [][green]string[white]{
|
||||
|
@ -23,14 +23,14 @@ const form = `[green]package[white] main
|
|||
[yellow]AddPasswordField[white]([red]"Password:"[white], [red]""[white], [red]10[white], [red]'*'[white], nil).
|
||||
[yellow]AddButton[white]([red]"Save"[white], [yellow]func[white]() { [blue]/* Save data */[white] }).
|
||||
[yellow]AddButton[white]([red]"Cancel"[white], [yellow]func[white]() { [blue]/* Cancel */[white] })
|
||||
tview.[yellow]NewApplication[white]().
|
||||
cview.[yellow]NewApplication[white]().
|
||||
[yellow]SetRoot[white](form, true).
|
||||
[yellow]Run[white]()
|
||||
}`
|
||||
|
||||
// Form demonstrates forms.
|
||||
func Form(nextSlide func()) (title string, content tview.Primitive) {
|
||||
f := tview.NewForm().
|
||||
func Form(nextSlide func()) (title string, content cview.Primitive) {
|
||||
f := cview.NewForm().
|
||||
AddInputField("First name:", "", 20, nil, nil).
|
||||
AddInputField("Last name:", "", 20, nil, nil).
|
||||
AddDropDown("Role:", []string{"Engineer", "Manager", "Administration"}, 0, nil).
|
||||
|
|
|
@ -2,17 +2,17 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
// Grid demonstrates the grid layout.
|
||||
func Grid(nextSlide func()) (title string, content tview.Primitive) {
|
||||
func Grid(nextSlide func()) (title string, content cview.Primitive) {
|
||||
modalShown := false
|
||||
pages := tview.NewPages()
|
||||
pages := cview.NewPages()
|
||||
|
||||
newPrimitive := func(text string) tview.Primitive {
|
||||
return tview.NewTextView().
|
||||
SetTextAlign(tview.AlignCenter).
|
||||
newPrimitive := func(text string) cview.Primitive {
|
||||
return cview.NewTextView().
|
||||
SetTextAlign(cview.AlignCenter).
|
||||
SetText(text).
|
||||
SetDoneFunc(func(key tcell.Key) {
|
||||
if modalShown {
|
||||
|
@ -29,7 +29,7 @@ func Grid(nextSlide func()) (title string, content tview.Primitive) {
|
|||
main := newPrimitive("Main content")
|
||||
sideBar := newPrimitive("Side Bar")
|
||||
|
||||
grid := tview.NewGrid().
|
||||
grid := cview.NewGrid().
|
||||
SetRows(3, 0, 3).
|
||||
SetColumns(0, -4, 0).
|
||||
SetBorders(true).
|
||||
|
@ -46,7 +46,7 @@ func Grid(nextSlide func()) (title string, content tview.Primitive) {
|
|||
AddItem(main, 1, 1, 1, 1, 0, 100, false).
|
||||
AddItem(sideBar, 1, 2, 1, 1, 0, 100, false)
|
||||
|
||||
modal := tview.NewModal().
|
||||
modal := cview.NewModal().
|
||||
SetText("Resize the window to see how the grid layout adapts").
|
||||
AddButtons([]string{"Ok"}).SetDoneFunc(func(buttonIndex int, buttonLabel string) {
|
||||
pages.HidePage("modal")
|
||||
|
|
|
@ -2,28 +2,28 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
const helloWorld = `[green]package[white] main
|
||||
|
||||
[green]import[white] (
|
||||
[red]"github.com/rivo/tview"[white]
|
||||
[red]"git.sr.ht/~tslocum/cview"[white]
|
||||
)
|
||||
|
||||
[green]func[white] [yellow]main[white]() {
|
||||
box := tview.[yellow]NewBox[white]().
|
||||
box := cview.[yellow]NewBox[white]().
|
||||
[yellow]SetBorder[white](true).
|
||||
[yellow]SetTitle[white]([red]"Hello, world!"[white])
|
||||
tview.[yellow]NewApplication[white]().
|
||||
cview.[yellow]NewApplication[white]().
|
||||
[yellow]SetRoot[white](box, true).
|
||||
[yellow]Run[white]()
|
||||
}`
|
||||
|
||||
// HelloWorld shows a simple "Hello world" example.
|
||||
func HelloWorld(nextSlide func()) (title string, content tview.Primitive) {
|
||||
func HelloWorld(nextSlide func()) (title string, content cview.Primitive) {
|
||||
// We use a text view because we want to capture keyboard input.
|
||||
textView := tview.NewTextView().SetDoneFunc(func(key tcell.Key) {
|
||||
textView := cview.NewTextView().SetDoneFunc(func(key tcell.Key) {
|
||||
nextSlide()
|
||||
})
|
||||
textView.SetBorder(true).SetTitle("Hello, world!")
|
||||
|
|
|
@ -2,7 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"git.sr.ht/~tslocum/cview"
|
||||
)
|
||||
|
||||
const inputField = `[green]package[white] main
|
||||
|
@ -11,29 +11,29 @@ const inputField = `[green]package[white] main
|
|||
[red]"strconv"[white]
|
||||
|
||||
[red]"github.com/gdamore/tcell"[white]
|
||||
[red]"github.com/rivo/tview"[white]
|
||||
[red]"git.sr.ht/~tslocum/cview"[white]
|
||||
)
|
||||
|
||||
[green]func[white] [yellow]main[white]() {
|
||||
input := tview.[yellow]NewInputField[white]().
|
||||
input := cview.[yellow]NewInputField[white]().
|
||||
[yellow]SetLabel[white]([red]"Enter a number: "[white]).
|
||||
[yellow]SetAcceptanceFunc[white](
|
||||
tview.InputFieldInteger,
|
||||
cview.InputFieldInteger,
|
||||
).[yellow]SetDoneFunc[white]([yellow]func[white](key tcell.Key) {
|
||||
text := input.[yellow]GetText[white]()
|
||||
n, _ := strconv.[yellow]Atoi[white](text)
|
||||
[blue]// We have a number.[white]
|
||||
})
|
||||
tview.[yellow]NewApplication[white]().
|
||||
cview.[yellow]NewApplication[white]().
|
||||
[yellow]SetRoot[white](input, true).
|
||||
[yellow]Run[white]()
|
||||
}`
|
||||
|
||||
// InputField demonstrates the InputField.
|
||||
func InputField(nextSlide func()) (title string, content tview.Primitive) {
|
||||
input := tview.NewInputField().
|
||||
func InputField(nextSlide func()) (title string, content cview.Primitive) {
|
||||
input := cview.NewInputField().
|
||||
SetLabel("Enter a number: ").
|
||||
SetAcceptanceFunc(tview.InputFieldInteger).SetDoneFunc(func(key tcell.Key) {
|
||||
SetAcceptanceFunc(cview.InputFieldInteger).SetDoneFunc(func(key tcell.Key) {
|
||||
nextSlide()
|
||||
})
|
||||
return "Input", Code(input, 30, 1, inputField)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package main
|
||||
|
||||
import "github.com/rivo/tview"
|
||||
import "git.sr.ht/~tslocum/cview"
|
||||
|
||||
// Introduction returns a tview.List with the highlights of the tview package.
|
||||
func Introduction(nextSlide func()) (title string, content tview.Primitive) {
|
||||
list := tview.NewList().
|
||||
// Introduction returns a cview.List with the highlights of the cview package.
|
||||
func Introduction(nextSlide func()) (title string, content cview.Primitive) {
|
||||
list := cview.NewList().
|
||||
AddItem("A Go package for terminal based UIs", "with a special focus on rich interactive widgets", '1', nextSlide).
|
||||
AddItem("Based on github.com/gdamore/tcell", "Like termbox but better (see tcell docs)", '2', nextSlide).
|
||||
AddItem("Designed to be simple", `"Hello world" is 5 lines of code`, '3', nextSlide).
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
A presentation of the tview package, implemented with tview.
|
||||
A presentation of the cview package, implemented with cview.
|
||||
|
||||
Navigation
|
||||
|
||||
|
@ -17,16 +17,16 @@ import (
|
|||
"strconv"
|
||||