diff --git a/.builds/amd64_freebsd.yml b/.builds/amd64_freebsd.yml new file mode 100644 index 0000000..7c473cf --- /dev/null +++ b/.builds/amd64_freebsd.yml @@ -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 ./... diff --git a/.builds/amd64_linux_alpine.yml b/.builds/amd64_linux_alpine.yml new file mode 100644 index 0000000..fe64726 --- /dev/null +++ b/.builds/amd64_linux_alpine.yml @@ -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 ./... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..66a9a59 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea/ +dist/ +*.sh +vendor/ diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index 601e63b..0000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 92f6886..95824c4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/FORK.md b/FORK.md new file mode 100644 index 0000000..944a7aa --- /dev/null +++ b/FORK.md @@ -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* diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..00d510c --- /dev/null +++ b/LICENSE @@ -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 + +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. diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index 9d69430..0000000 --- a/LICENSE.txt +++ /dev/null @@ -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. diff --git a/README.md b/README.md index ddceec7..38c3a1d 100644 --- a/README.md +++ b/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 diff --git a/ansi.go b/ansi.go index 4d0b2d9..346450a 100644 --- a/ansi.go +++ b/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) diff --git a/application.go b/application.go index 05a4357..7860671 100644 --- a/application.go +++ b/application.go @@ -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 { diff --git a/borders.go b/borders.go index 946c878..cc0a940 100644 --- a/borders.go +++ b/borders.go @@ -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. diff --git a/box.go b/box.go index cc0e160..45a9f1a 100644 --- a/box.go +++ b/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 diff --git a/button.go b/button.go index d3a6aed..acc6e6d 100644 --- a/button.go +++ b/button.go @@ -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 diff --git a/checkbox.go b/checkbox.go index 8f099d8..91b01bd 100644 --- a/checkbox.go +++ b/checkbox.go @@ -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 diff --git a/tview.gif b/cview.gif similarity index 100% rename from tview.gif rename to cview.gif diff --git a/demos/box/main.go b/demos/box/main.go index 8f4ec19..efa807e 100644 --- a/demos/box/main.go +++ b/demos/box/main.go @@ -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) } } diff --git a/demos/button/main.go b/demos/button/main.go index 429b5be..757835c 100644 --- a/demos/button/main.go +++ b/demos/button/main.go @@ -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) diff --git a/demos/checkbox/main.go b/demos/checkbox/main.go index ef9ef8e..6ef31ce 100644 --- a/demos/checkbox/main.go +++ b/demos/checkbox/main.go @@ -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) } diff --git a/demos/dropdown/main.go b/demos/dropdown/main.go index be9db66..23b8279 100644 --- a/demos/dropdown/main.go +++ b/demos/dropdown/main.go @@ -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 { diff --git a/demos/flex/main.go b/demos/flex/main.go index 1c22172..9b81194 100644 --- a/demos/flex/main.go +++ b/demos/flex/main.go @@ -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) } diff --git a/demos/form/main.go b/demos/form/main.go index e64614f..4129048 100644 --- a/demos/form/main.go +++ b/demos/form/main.go @@ -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) } diff --git a/demos/frame/main.go b/demos/frame/main.go index 9b03e64..a5e5706 100644 --- a/demos/frame/main.go +++ b/demos/frame/main.go @@ -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) } diff --git a/demos/grid/main.go b/demos/grid/main.go index cbdb1df..7a84253 100644 --- a/demos/grid/main.go +++ b/demos/grid/main.go @@ -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) } } diff --git a/demos/inputfield/autocomplete.go b/demos/inputfield/autocomplete/main.go similarity index 98% rename from demos/inputfield/autocomplete.go rename to demos/inputfield/autocomplete/main.go index 3437112..9ca78e7 100644 --- a/demos/inputfield/autocomplete.go +++ b/demos/inputfield/autocomplete/main.go @@ -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) { diff --git a/demos/inputfield/autocompleteasync.go b/demos/inputfield/autocompleteasync/main.go similarity index 94% rename from demos/inputfield/autocompleteasync.go rename to demos/inputfield/autocompleteasync/main.go index 9831c03..27c67a9 100644 --- a/demos/inputfield/autocompleteasync.go +++ b/demos/inputfield/autocompleteasync/main.go @@ -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) { diff --git a/demos/inputfield/main.go b/demos/inputfield/simple/main.go similarity index 69% rename from demos/inputfield/main.go rename to demos/inputfield/simple/main.go index b5ccd77..ba06379 100644 --- a/demos/inputfield/main.go +++ b/demos/inputfield/simple/main.go @@ -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() }) diff --git a/demos/list/main.go b/demos/list/main.go index 50cae17..04d8dbc 100644 --- a/demos/list/main.go +++ b/demos/list/main.go @@ -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). diff --git a/demos/modal/main.go b/demos/modal/main.go index 893230d..dfc9c25 100644 --- a/demos/modal/main.go +++ b/demos/modal/main.go @@ -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) { diff --git a/demos/pages/main.go b/demos/pages/main.go index 8eb67ab..fd8c104 100644 --- a/demos/pages/main.go +++ b/demos/pages/main.go @@ -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) { diff --git a/demos/presentation/center.go b/demos/presentation/center.go index b597b1c..1c75474 100644 --- a/demos/presentation/center.go +++ b/demos/presentation/center.go @@ -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) } diff --git a/demos/presentation/code.go b/demos/presentation/code.go index 59fd048..aeaa82b 100644 --- a/demos/presentation/code.go +++ b/demos/presentation/code.go @@ -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) } diff --git a/demos/presentation/colors.go b/demos/presentation/colors.go index 8e4bc48..1b77bf1 100644 --- a/demos/presentation/colors.go +++ b/demos/presentation/colors.go @@ -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) { diff --git a/demos/presentation/cover.go b/demos/presentation/cover.go index 2c06e5c..797f51d 100644 --- a/demos/presentation/cover.go +++ b/demos/presentation/cover.go @@ -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 diff --git a/demos/presentation/end.go b/demos/presentation/end.go index 119b676..c462cda 100644 --- a/demos/presentation/end.go +++ b/demos/presentation/end.go @@ -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) } diff --git a/demos/presentation/flex.go b/demos/presentation/flex.go index 22638c7..8091c73 100644 --- a/demos/presentation/flex.go +++ b/demos/presentation/flex.go @@ -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") diff --git a/demos/presentation/form.go b/demos/presentation/form.go index f2b0c0f..ab28b5f 100644 --- a/demos/presentation/form.go +++ b/demos/presentation/form.go @@ -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). diff --git a/demos/presentation/grid.go b/demos/presentation/grid.go index fc05521..8f5d728 100644 --- a/demos/presentation/grid.go +++ b/demos/presentation/grid.go @@ -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") diff --git a/demos/presentation/helloworld.go b/demos/presentation/helloworld.go index f312a79..a3fc325 100644 --- a/demos/presentation/helloworld.go +++ b/demos/presentation/helloworld.go @@ -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!") diff --git a/demos/presentation/inputfield.go b/demos/presentation/inputfield.go index 9700041..d23f629 100644 --- a/demos/presentation/inputfield.go +++ b/demos/presentation/inputfield.go @@ -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) diff --git a/demos/presentation/introduction.go b/demos/presentation/introduction.go index 8dc0f0c..9f88820 100644 --- a/demos/presentation/introduction.go +++ b/demos/presentation/introduction.go @@ -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). diff --git a/demos/presentation/main.go b/demos/presentation/main.go index c75fdc0..933bb1e 100644 --- a/demos/presentation/main.go +++ b/demos/presentation/main.go @@ -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" "github.com/gdamore/tcell" - "github.com/rivo/tview" + "git.sr.ht/~tslocum/cview" ) // Slide is a function which returns the slide's main primitive and its title. // It receives a "nextSlide" function which can be called to advance the // presentation to the next slide. -type Slide func(nextSlide func()) (title string, content tview.Primitive) +type Slide func(nextSlide func()) (title string, content cview.Primitive) // The application. -var app = tview.NewApplication() +var app = cview.NewApplication() // Starting point for the presentation. func main() { @@ -48,7 +48,7 @@ func main() { } // The bottom row has some info on where we are. - info := tview.NewTextView(). + info := cview.NewTextView(). SetDynamicColors(true). SetRegions(true). SetWrap(false) @@ -56,7 +56,7 @@ func main() { // Create the pages for all slides. currentSlide := 0 info.Highlight(strconv.Itoa(currentSlide)) - pages := tview.NewPages() + pages := cview.NewPages() previousSlide := func() { currentSlide = (currentSlide - 1 + len(slides)) % len(slides) info.Highlight(strconv.Itoa(currentSlide)). @@ -76,8 +76,8 @@ func main() { } // Create the main layout. - layout := tview.NewFlex(). - SetDirection(tview.FlexRow). + layout := cview.NewFlex(). + SetDirection(cview.FlexRow). AddItem(pages, 0, 1, true). AddItem(info, 1, 1, false) diff --git a/demos/presentation/table.go b/demos/presentation/table.go index 798c11c..e45d36f 100644 --- a/demos/presentation/table.go +++ b/demos/presentation/table.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/gdamore/tcell" - "github.com/rivo/tview" + "git.sr.ht/~tslocum/cview" ) const tableData = `OrderDate|Region|Rep|Item|Units|UnitCost|Total @@ -54,7 +54,7 @@ const tableData = `OrderDate|Region|Rep|Item|Units|UnitCost|Total 12/21/2018|Central|Andrews|Binder|28|4.99|139.72` const tableBasic = `[green]func[white] [yellow]main[white]() { - table := tview.[yellow]NewTable[white](). + table := cview.[yellow]NewTable[white](). [yellow]SetFixed[white]([red]1[white], [red]1[white]) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { [yellow]for[white] column := [red]0[white]; column < [red]7[white]; column++ { @@ -64,28 +64,28 @@ const tableBasic = `[green]func[white] [yellow]main[white]() { } [yellow]else[white] [yellow]if[white] column == [red]0[white] { color = tcell.ColorDarkCyan } - align := tview.AlignLeft + align := cview.AlignLeft [yellow]if[white] row == [red]0[white] { - align = tview.AlignCenter + align = cview.AlignCenter } [yellow]else[white] [yellow]if[white] column == [red]0[white] || column >= [red]4[white] { - align = tview.AlignRight + align = cview.AlignRight } table.[yellow]SetCell[white](row, column, - &tview.TableCell{ + &cview.TableCell{ Text: [red]"..."[white], Color: color, Align: align, }) } } - tview.[yellow]NewApplication[white](). + cview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). [yellow]Run[white]() }` const tableSeparator = `[green]func[white] [yellow]main[white]() { - table := tview.[yellow]NewTable[white](). + table := cview.[yellow]NewTable[white](). [yellow]SetFixed[white]([red]1[white], [red]1[white]). [yellow]SetSeparator[white](Borders.Vertical) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { @@ -96,28 +96,28 @@ const tableSeparator = `[green]func[white] [yellow]main[white]() { } [yellow]else[white] [yellow]if[white] column == [red]0[white] { color = tcell.ColorDarkCyan } - align := tview.AlignLeft + align := cview.AlignLeft [yellow]if[white] row == [red]0[white] { - align = tview.AlignCenter + align = cview.AlignCenter } [yellow]else[white] [yellow]if[white] column == [red]0[white] || column >= [red]4[white] { - align = tview.AlignRight + align = cview.AlignRight } table.[yellow]SetCell[white](row, column, - &tview.TableCell{ + &cview.TableCell{ Text: [red]"..."[white], Color: color, Align: align, }) } } - tview.[yellow]NewApplication[white](). + cview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). [yellow]Run[white]() }` const tableBorders = `[green]func[white] [yellow]main[white]() { - table := tview.[yellow]NewTable[white](). + table := cview.[yellow]NewTable[white](). [yellow]SetFixed[white]([red]1[white], [red]1[white]). [yellow]SetBorders[white](true) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { @@ -128,28 +128,28 @@ const tableBorders = `[green]func[white] [yellow]main[white]() { } [yellow]else[white] [yellow]if[white] column == [red]0[white] { color = tcell.ColorDarkCyan } - align := tview.AlignLeft + align := cview.AlignLeft [yellow]if[white] row == [red]0[white] { - align = tview.AlignCenter + align = cview.AlignCenter } [yellow]else[white] [yellow]if[white] column == [red]0[white] || column >= [red]4[white] { - align = tview.AlignRight + align = cview.AlignRight } table.[yellow]SetCell[white](row, column, - &tview.TableCell{ + &cview.TableCell{ Text: [red]"..."[white], Color: color, Align: align, }) } } - tview.[yellow]NewApplication[white](). + cview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). [yellow]Run[white]() }` const tableSelectRow = `[green]func[white] [yellow]main[white]() { - table := tview.[yellow]NewTable[white](). + table := cview.[yellow]NewTable[white](). [yellow]SetFixed[white]([red]1[white], [red]1[white]). [yellow]SetSelectable[white](true, false) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { @@ -160,15 +160,15 @@ const tableSelectRow = `[green]func[white] [yellow]main[white]() { } [yellow]else[white] [yellow]if[white] column == [red]0[white] { color = tcell.ColorDarkCyan } - align := tview.AlignLeft + align := cview.AlignLeft [yellow]if[white] row == [red]0[white] { - align = tview.AlignCenter + align = cview.AlignCenter } [yellow]else[white] [yellow]if[white] column == [red]0[white] || column >= [red]4[white] { - align = tview.AlignRight + align = cview.AlignRight } table.[yellow]SetCell[white](row, column, - &tview.TableCell{ + &cview.TableCell{ Text: [red]"..."[white], Color: color, Align: align, @@ -176,13 +176,13 @@ const tableSelectRow = `[green]func[white] [yellow]main[white]() { }) } } - tview.[yellow]NewApplication[white](). + cview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). [yellow]Run[white]() }` const tableSelectColumn = `[green]func[white] [yellow]main[white]() { - table := tview.[yellow]NewTable[white](). + table := cview.[yellow]NewTable[white](). [yellow]SetFixed[white]([red]1[white], [red]1[white]). [yellow]SetSelectable[white](false, true) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { @@ -193,15 +193,15 @@ const tableSelectColumn = `[green]func[white] [yellow]main[white]() { } [yellow]else[white] [yellow]if[white] column == [red]0[white] { color = tcell.ColorDarkCyan } - align := tview.AlignLeft + align := cview.AlignLeft [yellow]if[white] row == [red]0[white] { - align = tview.AlignCenter + align = cview.AlignCenter } [yellow]else[white] [yellow]if[white] column == [red]0[white] || column >= [red]4[white] { - align = tview.AlignRight + align = cview.AlignRight } table.[yellow]SetCell[white](row, column, - &tview.TableCell{ + &cview.TableCell{ Text: [red]"..."[white], Color: color, Align: align, @@ -209,13 +209,13 @@ const tableSelectColumn = `[green]func[white] [yellow]main[white]() { }) } } - tview.[yellow]NewApplication[white](). + cview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). [yellow]Run[white]() }` const tableSelectCell = `[green]func[white] [yellow]main[white]() { - table := tview.[yellow]NewTable[white](). + table := cview.[yellow]NewTable[white](). [yellow]SetFixed[white]([red]1[white], [red]1[white]). [yellow]SetSelectable[white](true, true) [yellow]for[white] row := [red]0[white]; row < [red]40[white]; row++ { @@ -226,15 +226,15 @@ const tableSelectCell = `[green]func[white] [yellow]main[white]() { } [yellow]else[white] [yellow]if[white] column == [red]0[white] { color = tcell.ColorDarkCyan } - align := tview.AlignLeft + align := cview.AlignLeft [yellow]if[white] row == [red]0[white] { - align = tview.AlignCenter + align = cview.AlignCenter } [yellow]else[white] [yellow]if[white] column == [red]0[white] || column >= [red]4[white] { - align = tview.AlignRight + align = cview.AlignRight } table.[yellow]SetCell[white](row, column, - &tview.TableCell{ + &cview.TableCell{ Text: [red]"..."[white], Color: color, Align: align, @@ -242,14 +242,14 @@ const tableSelectCell = `[green]func[white] [yellow]main[white]() { }) } } - tview.[yellow]NewApplication[white](). + cview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). [yellow]Run[white]() }` // Table demonstrates the Table. -func Table(nextSlide func()) (title string, content tview.Primitive) { - table := tview.NewTable(). +func Table(nextSlide func()) (title string, content cview.Primitive) { + table := cview.NewTable(). SetFixed(1, 1) for row, line := range strings.Split(tableData, "\n") { for column, cell := range strings.Split(line, "|") { @@ -259,13 +259,13 @@ func Table(nextSlide func()) (title string, content tview.Primitive) { } else if column == 0 { color = tcell.ColorDarkCyan } - align := tview.AlignLeft + align := cview.AlignLeft if row == 0 { - align = tview.AlignCenter + align = cview.AlignCenter } else if column == 0 || column >= 4 { - align = tview.AlignRight + align = cview.AlignRight } - tableCell := tview.NewTableCell(cell). + tableCell := cview.NewTableCell(cell). SetTextColor(color). SetAlign(align). SetSelectable(row != 0 && column != 0) @@ -277,12 +277,12 @@ func Table(nextSlide func()) (title string, content tview.Primitive) { } table.SetBorder(true).SetTitle("Table") - code := tview.NewTextView(). + code := cview.NewTextView(). SetWrap(false). SetDynamicColors(true) code.SetBorderPadding(1, 1, 2, 0) - list := tview.NewList() + list := cview.NewList() basic := func() { table.SetBorders(false). @@ -295,7 +295,7 @@ func Table(nextSlide func()) (title string, content tview.Primitive) { separator := func() { table.SetBorders(false). SetSelectable(false, false). - SetSeparator(tview.Borders.Vertical) + SetSeparator(cview.Borders.Vertical) code.Clear() fmt.Fprint(code, tableSeparator) } @@ -353,9 +353,9 @@ func Table(nextSlide func()) (title string, content tview.Primitive) { basic() - return "Table", tview.NewFlex(). - AddItem(tview.NewFlex(). - SetDirection(tview.FlexRow). + return "Table", cview.NewFlex(). + AddItem(cview.NewFlex(). + SetDirection(cview.FlexRow). AddItem(list, 10, 1, true). AddItem(table, 0, 1, false), 0, 1, true). AddItem(code, codeWidth, 1, false) diff --git a/demos/presentation/textview.go b/demos/presentation/textview.go index 666dfe7..55d231e 100644 --- a/demos/presentation/textview.go +++ b/demos/presentation/textview.go @@ -6,12 +6,12 @@ import ( "time" "github.com/gdamore/tcell" - "github.com/rivo/tview" + "git.sr.ht/~tslocum/cview" ) const textView1 = `[green]func[white] [yellow]main[white]() { - app := tview.[yellow]NewApplication[white]() - textView := tview.[yellow]NewTextView[white](). + app := cview.[yellow]NewApplication[white]() + textView := cview.[yellow]NewTextView[white](). [yellow]SetTextColor[white](tcell.ColorYellow). [yellow]SetScrollable[white](false). [yellow]SetChangedFunc[white]([yellow]func[white]() { @@ -30,8 +30,8 @@ const textView1 = `[green]func[white] [yellow]main[white]() { }` // TextView1 demonstrates the basic text view. -func TextView1(nextSlide func()) (title string, content tview.Primitive) { - textView := tview.NewTextView(). +func TextView1(nextSlide func()) (title string, content cview.Primitive) { + textView := cview.NewTextView(). SetTextColor(tcell.ColorYellow). SetScrollable(false). SetDoneFunc(func(key tcell.Key) { @@ -60,11 +60,11 @@ const textView2 = `[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]() { - ["0"]textView[""] := tview.[yellow]NewTextView[white]() + ["0"]textView[""] := cview.[yellow]NewTextView[white]() ["1"]textView[""].[yellow]SetDynamicColors[white](true). [yellow]SetWrap[white](false). [yellow]SetRegions[white](true). @@ -96,19 +96,19 @@ const textView2 = `[green]package[white] main } }) fmt.[yellow]Fprint[white](["7"]textView[""], content) - tview.[yellow]NewApplication[white](). + cview.[yellow]NewApplication[white](). [yellow]SetRoot[white](["8"]textView[""], true). [yellow]Run[white]() }` // TextView2 demonstrates the extended text view. -func TextView2(nextSlide func()) (title string, content tview.Primitive) { - codeView := tview.NewTextView(). +func TextView2(nextSlide func()) (title string, content cview.Primitive) { + codeView := cview.NewTextView(). SetWrap(false) fmt.Fprint(codeView, textView2) codeView.SetBorder(true).SetTitle("Buffer content") - textView := tview.NewTextView() + textView := cview.NewTextView() textView.SetDynamicColors(true). SetWrap(false). SetRegions(true). @@ -145,7 +145,7 @@ func TextView2(nextSlide func()) (title string, content tview.Primitive) { }) fmt.Fprint(textView, textView2) textView.SetBorder(true).SetTitle("TextView output") - return "Text 2", tview.NewFlex(). + return "Text 2", cview.NewFlex(). AddItem(textView, 0, 1, true). AddItem(codeView, 0, 1, false) } diff --git a/demos/presentation/treeview.go b/demos/presentation/treeview.go index 68349cd..de1b973 100644 --- a/demos/presentation/treeview.go +++ b/demos/presentation/treeview.go @@ -4,42 +4,42 @@ import ( "strings" "github.com/gdamore/tcell" - "github.com/rivo/tview" + "git.sr.ht/~tslocum/cview" ) const treeAllCode = `[green]package[white] main -[green]import[white] [red]"github.com/rivo/tview"[white] +[green]import[white] [red]"git.sr.ht/~tslocum/cview"[white] [green]func[white] [yellow]main[white]() { $$$ - root := tview.[yellow]NewTreeNode[white]([red]"Root"[white]). - [yellow]AddChild[white](tview.[yellow]NewTreeNode[white]([red]"First child"[white]). - [yellow]AddChild[white](tview.[yellow]NewTreeNode[white]([red]"Grandchild A"[white])). - [yellow]AddChild[white](tview.[yellow]NewTreeNode[white]([red]"Grandchild B"[white]))). - [yellow]AddChild[white](tview.[yellow]NewTreeNode[white]([red]"Second child"[white]). - [yellow]AddChild[white](tview.[yellow]NewTreeNode[white]([red]"Grandchild C"[white])). - [yellow]AddChild[white](tview.[yellow]NewTreeNode[white]([red]"Grandchild D"[white]))). - [yellow]AddChild[white](tview.[yellow]NewTreeNode[white]([red]"Third child"[white])) + root := cview.[yellow]NewTreeNode[white]([red]"Root"[white]). + [yellow]AddChild[white](cview.[yellow]NewTreeNode[white]([red]"First child"[white]). + [yellow]AddChild[white](cview.[yellow]NewTreeNode[white]([red]"Grandchild A"[white])). + [yellow]AddChild[white](cview.[yellow]NewTreeNode[white]([red]"Grandchild B"[white]))). + [yellow]AddChild[white](cview.[yellow]NewTreeNode[white]([red]"Second child"[white]). + [yellow]AddChild[white](cview.[yellow]NewTreeNode[white]([red]"Grandchild C"[white])). + [yellow]AddChild[white](cview.[yellow]NewTreeNode[white]([red]"Grandchild D"[white]))). + [yellow]AddChild[white](cview.[yellow]NewTreeNode[white]([red]"Third child"[white])) tree.[yellow]SetRoot[white](root). [yellow]SetCurrentNode[white](root) - tview.[yellow]NewApplication[white](). + cview.[yellow]NewApplication[white](). [yellow]SetRoot[white](tree, true). [yellow]Run[white]() }` -const treeBasicCode = `tree := tview.[yellow]NewTreeView[white]()` +const treeBasicCode = `tree := cview.[yellow]NewTreeView[white]()` -const treeTopLevelCode = `tree := tview.[yellow]NewTreeView[white](). +const treeTopLevelCode = `tree := cview.[yellow]NewTreeView[white](). [yellow]SetTopLevel[white]([red]1[white])` -const treeAlignCode = `tree := tview.[yellow]NewTreeView[white](). +const treeAlignCode = `tree := cview.[yellow]NewTreeView[white](). [yellow]SetAlign[white](true)` -const treePrefixCode = `tree := tview.[yellow]NewTreeView[white](). +const treePrefixCode = `tree := cview.[yellow]NewTreeView[white](). [yellow]SetGraphics[white](false). [yellow]SetTopLevel[white]([red]1[white]). [yellow]SetPrefixes[white]([][green]string[white]{ @@ -56,9 +56,9 @@ type node struct { } var ( - tree = tview.NewTreeView() + tree = cview.NewTreeView() treeNextSlide func() - treeCode = tview.NewTextView().SetWrap(false).SetDynamicColors(true) + treeCode = cview.NewTextView().SetWrap(false).SetDynamicColors(true) ) var rootNode = &node{ @@ -106,15 +106,15 @@ var rootNode = &node{ }} // TreeView demonstrates the tree view. -func TreeView(nextSlide func()) (title string, content tview.Primitive) { +func TreeView(nextSlide func()) (title string, content cview.Primitive) { treeNextSlide = nextSlide tree.SetBorder(true). SetTitle("TreeView") // Add nodes. - var add func(target *node) *tview.TreeNode - add = func(target *node) *tview.TreeNode { - node := tview.NewTreeNode(target.text). + var add func(target *node) *cview.TreeNode + add = func(target *node) *cview.TreeNode { + node := cview.NewTreeNode(target.text). SetSelectable(target.expand || target.selected != nil). SetExpanded(target == rootNode). SetReference(target) @@ -131,7 +131,7 @@ func TreeView(nextSlide func()) (title string, content tview.Primitive) { root := add(rootNode) tree.SetRoot(root). SetCurrentNode(root). - SetSelectedFunc(func(n *tview.TreeNode) { + SetSelectedFunc(func(n *cview.TreeNode) { original := n.GetReference().(*node) if original.expand { n.SetExpanded(!n.IsExpanded()) @@ -143,7 +143,7 @@ func TreeView(nextSlide func()) (title string, content tview.Primitive) { treeCode.SetText(strings.Replace(treeAllCode, "$$$", treeBasicCode, -1)). SetBorderPadding(1, 1, 2, 0) - return "Tree", tview.NewFlex(). + return "Tree", cview.NewFlex(). AddItem(tree, 0, 1, true). AddItem(treeCode, codeWidth, 1, false) } diff --git a/demos/primitive/main.go b/demos/primitive/main.go index e2d911a..8ff2aca 100644 --- a/demos/primitive/main.go +++ b/demos/primitive/main.go @@ -5,12 +5,12 @@ import ( "fmt" "github.com/gdamore/tcell" - "github.com/rivo/tview" + "git.sr.ht/~tslocum/cview" ) // RadioButtons implements a simple primitive for radio button selections. type RadioButtons struct { - *tview.Box + *cview.Box options []string currentOption int } @@ -18,7 +18,7 @@ type RadioButtons struct { // NewRadioButtons returns a new radio button primitive. func NewRadioButtons(options []string) *RadioButtons { return &RadioButtons{ - Box: tview.NewBox(), + Box: cview.NewBox(), options: options, } } @@ -37,13 +37,13 @@ func (r *RadioButtons) Draw(screen tcell.Screen) { radioButton = "\u25c9" // Checked. } line := fmt.Sprintf(`%s[white] %s`, radioButton, option) - tview.Print(screen, line, x, y+index, width, tview.AlignLeft, tcell.ColorYellow) + cview.Print(screen, line, x, y+index, width, cview.AlignLeft, tcell.ColorYellow) } } // InputHandler returns the handler for this primitive. -func (r *RadioButtons) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive)) { - return r.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p tview.Primitive)) { +func (r *RadioButtons) InputHandler() func(event *tcell.EventKey, setFocus func(p cview.Primitive)) { + return r.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p cview.Primitive)) { switch event.Key() { case tcell.KeyUp: r.currentOption-- @@ -64,7 +64,7 @@ func main() { radioButtons.SetBorder(true). SetTitle("Radio Button Demo"). SetRect(0, 0, 30, 5) - if err := tview.NewApplication().SetRoot(radioButtons, false).Run(); err != nil { + if err := cview.NewApplication().SetRoot(radioButtons, false).Run(); err != nil { panic(err) } } diff --git a/demos/table/main.go b/demos/table/main.go index 38cb0c1..9565dc6 100644 --- a/demos/table/main.go +++ b/demos/table/main.go @@ -5,12 +5,12 @@ import ( "strings" "github.com/gdamore/tcell" - "github.com/rivo/tview" + "git.sr.ht/~tslocum/cview" ) func main() { - app := tview.NewApplication() - table := tview.NewTable(). + app := cview.NewApplication() + table := cview.NewTable(). SetBorders(true) lorem := strings.Split("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.", " ") cols, rows := 10, 40 @@ -22,9 +22,9 @@ func main() { color = tcell.ColorYellow } table.SetCell(r, c, - tview.NewTableCell(lorem[word]). + cview.NewTableCell(lorem[word]). SetTextColor(color). - SetAlign(tview.AlignCenter)) + SetAlign(cview.AlignCenter)) word = (word + 1) % len(lorem) } } diff --git a/demos/textview/main.go b/demos/textview/main.go index 66cc45e..27da0cf 100644 --- a/demos/textview/main.go +++ b/demos/textview/main.go @@ -8,7 +8,7 @@ import ( "time" "github.com/gdamore/tcell" - "github.com/rivo/tview" + "git.sr.ht/~tslocum/cview" ) const corporate = `Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment. @@ -20,8 +20,8 @@ Capitalize on low hanging fruit to identify a ballpark value added activity to b [yellow]Press Enter, then Tab/Backtab for word selections` func main() { - app := tview.NewApplication() - textView := tview.NewTextView(). + app := cview.NewApplication() + textView := cview.NewTextView(). SetDynamicColors(true). SetRegions(true). SetWordWrap(true). diff --git a/demos/treeview/main.go b/demos/treeview/main.go index bce3cba..6594204 100644 --- a/demos/treeview/main.go +++ b/demos/treeview/main.go @@ -6,27 +6,27 @@ import ( "path/filepath" "github.com/gdamore/tcell" - "github.com/rivo/tview" + "git.sr.ht/~tslocum/cview" ) // Show a navigable tree view of the current directory. func main() { rootDir := "." - root := tview.NewTreeNode(rootDir). + root := cview.NewTreeNode(rootDir). SetColor(tcell.ColorRed) - tree := tview.NewTreeView(). + tree := cview.NewTreeView(). SetRoot(root). SetCurrentNode(root) // A helper function which adds the files and directories of the given path // to the given target node. - add := func(target *tview.TreeNode, path string) { + add := func(target *cview.TreeNode, path string) { files, err := ioutil.ReadDir(path) if err != nil { panic(err) } for _, file := range files { - node := tview.NewTreeNode(file.Name()). + node := cview.NewTreeNode(file.Name()). SetReference(filepath.Join(path, file.Name())). SetSelectable(file.IsDir()) if file.IsDir() { @@ -40,7 +40,7 @@ func main() { add(root, rootDir) // If a directory was selected, open it. - tree.SetSelectedFunc(func(node *tview.TreeNode) { + tree.SetSelectedFunc(func(node *cview.TreeNode) { reference := node.GetReference() if reference == nil { return // Selecting the root node does nothing. @@ -56,7 +56,7 @@ func main() { } }) - if err := tview.NewApplication().SetRoot(tree, true).Run(); err != nil { + if err := cview.NewApplication().SetRoot(tree, true).Run(); err != nil { panic(err) } } diff --git a/demos/unicode/main.go b/demos/unicode/main.go index 761b100..e2815b0 100644 --- a/demos/unicode/main.go +++ b/demos/unicode/main.go @@ -4,28 +4,28 @@ package main import ( "fmt" - "github.com/rivo/tview" + "git.sr.ht/~tslocum/cview" ) func main() { - app := tview.NewApplication() - pages := tview.NewPages() + app := cview.NewApplication() + pages := cview.NewPages() - form := tview.NewForm() + form := cview.NewForm() form.AddDropDown("称谓", []string{"先生", "女士", "博士", "老师", "师傅"}, 0, nil). AddInputField("姓名", "", 20, nil, nil). AddCheckbox("年龄 18+", false, nil). AddPasswordField("密码", "", 10, '*', nil). AddButton("保存", func() { - _, title := form.GetFormItem(0).(*tview.DropDown).GetCurrentOption() - userName := form.GetFormItem(1).(*tview.InputField).GetText() + _, title := form.GetFormItem(0).(*cview.DropDown).GetCurrentOption() + userName := form.GetFormItem(1).(*cview.InputField).GetText() alert(pages, "alert-dialog", fmt.Sprintf("保存成功,%s %s!", userName, title)) }). AddButton("退出", func() { app.Stop() }) - form.SetBorder(true).SetTitle("输入一些内容").SetTitleAlign(tview.AlignLeft) + form.SetBorder(true).SetTitle("输入一些内容").SetTitleAlign(cview.AlignLeft) pages.AddPage("base", form, true, true) if err := app.SetRoot(pages, true).Run(); err != nil { @@ -34,10 +34,10 @@ func main() { } // alert shows a confirmation dialog. -func alert(pages *tview.Pages, id string, message string) *tview.Pages { +func alert(pages *cview.Pages, id string, message string) *cview.Pages { return pages.AddPage( id, - tview.NewModal(). + cview.NewModal(). SetText(message). AddButtons([]string{"确定"}). SetDoneFunc(func(buttonIndex int, buttonLabel string) { diff --git a/doc.go b/doc.go index 4bceea2..7702dc4 100644 --- a/doc.go +++ b/doc.go @@ -1,5 +1,5 @@ /* -Package tview implements rich widgets for terminal based user interfaces. The +Package cview implements rich widgets for terminal based user interfaces. The widgets provided with this package are useful for data exploration and data entry. @@ -36,12 +36,12 @@ world!": 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) } } @@ -59,7 +59,7 @@ actions performed on them. More Demos You will find more demos in the "demos" subdirectory. It also contains a -presentation (written using tview) which gives an overview of the different +presentation (written using cview) which gives an overview of the different widgets and how they can be used. Colors @@ -172,9 +172,9 @@ therefore available for all widgets, too. All widgets also implement the Primitive interface. There is also the Focusable interface which is used to override functions in subclassing types. -The tview package is based on https://github.com/gdamore/tcell. It uses types +The cview package is based on https://github.com/gdamore/tcell. It uses types and constants from that package (e.g. colors and keyboard values). This package does not process mouse input (yet). */ -package tview +package cview diff --git a/dropdown.go b/dropdown.go index 58eee24..455ea51 100644 --- a/dropdown.go +++ b/dropdown.go @@ -1,4 +1,4 @@ -package tview +package cview import ( "strings" @@ -15,7 +15,7 @@ type dropDownOption struct { // DropDown implements a selection widget whose options become visible in a // drop-down list when activated. // -// See https://github.com/rivo/tview/wiki/DropDown for an example. +// See https://git.sr.ht/~tslocum/cview/wiki/DropDown for an example. type DropDown struct { *Box diff --git a/flex.go b/flex.go index 56cbc75..6ab4a9c 100644 --- a/flex.go +++ b/flex.go @@ -1,4 +1,4 @@ -package tview +package cview import ( "github.com/gdamore/tcell" @@ -23,7 +23,7 @@ type flexItem struct { // distributed along that dimension depends on their layout settings, which is // either a fixed length or a proportional length. See AddItem() for details. // -// See https://github.com/rivo/tview/wiki/Flex for an example. +// See https://git.sr.ht/~tslocum/cview/wiki/Flex for an example. type Flex struct { *Box @@ -47,7 +47,7 @@ type Flex struct { // To clear a Flex's background before any items are drawn, set it to the // desired color: // -// flex.SetBackgroundColor(tview.Styles.PrimitiveBackgroundColor) +// flex.SetBackgroundColor(cview.Styles.PrimitiveBackgroundColor) func NewFlex() *Flex { f := &Flex{ Box: NewBox().SetBackgroundColor(tcell.ColorDefault), diff --git a/focusable.go b/focusable.go index 99fdaaf..1e6fee5 100644 --- a/focusable.go +++ b/focusable.go @@ -1,4 +1,4 @@ -package tview +package cview // Focusable provides a method which determines if a primitive has focus. // Composed primitives may be focused based on the focused state of their diff --git a/form.go b/form.go index 775b672..5009c59 100644 --- a/form.go +++ b/form.go @@ -1,4 +1,4 @@ -package tview +package cview import ( "github.com/gdamore/tcell" @@ -38,7 +38,7 @@ type FormItem interface { // Checkbox. These elements can be optionally followed by one or more buttons // for which you can define form-wide actions (e.g. Save, Clear, Cancel). // -// See https://github.com/rivo/tview/wiki/Form for an example. +// See https://git.sr.ht/~tslocum/cview/wiki/Form for an example. type Form struct { *Box diff --git a/frame.go b/frame.go index 77c5316..a9cb4f8 100644 --- a/frame.go +++ b/frame.go @@ -1,4 +1,4 @@ -package tview +package cview import ( "github.com/gdamore/tcell" @@ -15,7 +15,7 @@ type frameText struct { // Frame is a wrapper which adds a border around another primitive. The top area // (header) and the bottom area (footer) may also contain text. // -// See https://github.com/rivo/tview/wiki/Frame for an example. +// See https://git.sr.ht/~tslocum/cview/wiki/Frame for an example. type Frame struct { *Box diff --git a/go.mod b/go.mod index 3e601ac..10d5615 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/rivo/tview +module git.sr.ht/~tslocum/cview go 1.12 diff --git a/go.sum b/go.sum index d244f3c..a05489a 100644 --- a/go.sum +++ b/go.sum @@ -1,16 +1,13 @@ +github.com/DATA-DOG/go-sqlmock v1.3.3 h1:CWUqKXe0s8A2z6qCgkP4Kru7wC11YoAnoupUKFDnH08= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= -github.com/gdamore/tcell v1.1.2 h1:Afe8cU6SECC06UmvaJ55Jr3Eh0tz/ywLjqWYqjGZp3s= -github.com/gdamore/tcell v1.1.2/go.mod h1:h3kq4HO9l2On+V9ed8w8ewqQEmGCSSHOgQ+2h8uzurE= github.com/gdamore/tcell v1.3.0 h1:r35w0JBADPZCVQijYebl6YMWWtHRqVEGt7kL2eBADRM= github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM= github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4= github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s= github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/rivo/uniseg v0.0.0-20190513083848-b9f5b9457d44 h1:XKCbzPvK4/BbMXoMJOkYP2ANxiAEO0HM1xn6psSbXxY= -github.com/rivo/uniseg v0.0.0-20190513083848-b9f5b9457d44/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10= diff --git a/grid.go b/grid.go index 2494b13..66d0bf6 100644 --- a/grid.go +++ b/grid.go @@ -1,4 +1,4 @@ -package tview +package cview import ( "math" @@ -27,7 +27,7 @@ type gridItem struct { // and "l" keys) while the grid has focus and none of its contained primitives // do. // -// See https://github.com/rivo/tview/wiki/Grid for an example. +// See https://git.sr.ht/~tslocum/cview/wiki/Grid for an example. type Grid struct { *Box @@ -65,7 +65,7 @@ type Grid struct { // their background unchanged. To clear a Grid's background before any items are // drawn, set it to the desired color: // -// grid.SetBackgroundColor(tview.Styles.PrimitiveBackgroundColor) +// grid.SetBackgroundColor(cview.Styles.PrimitiveBackgroundColor) func NewGrid() *Grid { g := &Grid{ Box: NewBox().SetBackgroundColor(tcell.ColorDefault), diff --git a/inputfield.go b/inputfield.go index 3cd255e..06f736b 100644 --- a/inputfield.go +++ b/inputfield.go @@ -1,4 +1,4 @@ -package tview +package cview import ( "math" @@ -29,7 +29,7 @@ import ( // - Ctrl-W: Delete the last word before the cursor. // - Ctrl-U: Delete the entire line. // -// See https://github.com/rivo/tview/wiki/InputField for an example. +// See https://git.sr.ht/~tslocum/cview/wiki/InputField for an example. type InputField struct { *Box diff --git a/list.go b/list.go index 14ecf43..251b922 100644 --- a/list.go +++ b/list.go @@ -1,4 +1,4 @@ -package tview +package cview import ( "fmt" @@ -17,7 +17,7 @@ type listItem struct { // List displays rows of items, each of which can be selected. // -// See https://github.com/rivo/tview/wiki/List for an example. +// See https://git.sr.ht/~tslocum/cview/wiki/List for an example. type List struct { *Box diff --git a/modal.go b/modal.go index 2b10d94..a43763e 100644 --- a/modal.go +++ b/modal.go @@ -1,4 +1,4 @@ -package tview +package cview import ( "github.com/gdamore/tcell" @@ -8,7 +8,7 @@ import ( // for an immediate decision. It needs to have at least one button (added via // AddButtons()) or it will never disappear. // -// See https://github.com/rivo/tview/wiki/Modal for an example. +// See https://git.sr.ht/~tslocum/cview/wiki/Modal for an example. type Modal struct { *Box diff --git a/pages.go b/pages.go index 155da73..5c20fa4 100644 --- a/pages.go +++ b/pages.go @@ -1,4 +1,4 @@ -package tview +package cview import ( "github.com/gdamore/tcell" @@ -16,7 +16,7 @@ type page struct { // root primitive. It allows to easily switch the visibility of the contained // primitives. // -// See https://github.com/rivo/tview/wiki/Pages for an example. +// See https://git.sr.ht/~tslocum/cview/wiki/Pages for an example. type Pages struct { *Box diff --git a/primitive.go b/primitive.go index 88a9d46..5148e12 100644 --- a/primitive.go +++ b/primitive.go @@ -1,4 +1,4 @@ -package tview +package cview import "github.com/gdamore/tcell" diff --git a/semigraphics.go b/semigraphics.go index 3b66c5f..64f55ac 100644 --- a/semigraphics.go +++ b/semigraphics.go @@ -1,4 +1,4 @@ -package tview +package cview import "github.com/gdamore/tcell" diff --git a/styles.go b/styles.go index 4f0448f..e906e39 100644 --- a/styles.go +++ b/styles.go @@ -1,4 +1,4 @@ -package tview +package cview import "github.com/gdamore/tcell" diff --git a/table.go b/table.go index 9d0db29..a765de0 100644 --- a/table.go +++ b/table.go @@ -1,4 +1,4 @@ -package tview +package cview import ( "sort" @@ -208,7 +208,7 @@ func (c *TableCell) GetLastPosition() (x, y, width int) { // // Use SetInputCapture() to override or modify keyboard input. // -// See https://github.com/rivo/tview/wiki/Table for an example. +// See https://git.sr.ht/~tslocum/cview/wiki/Table for an example. type Table struct { *Box diff --git a/textview.go b/textview.go index 1e4a55f..4873022 100644 --- a/textview.go +++ b/textview.go @@ -1,4 +1,4 @@ -package tview +package cview import ( "bytes" @@ -88,7 +88,7 @@ type textViewIndex struct { // The ScrollToHighlight() function can be used to jump to the currently // highlighted region once when the text view is drawn the next time. // -// See https://github.com/rivo/tview/wiki/TextView for an example. +// See https://git.sr.ht/~tslocum/cview/wiki/TextView for an example. type TextView struct { sync.Mutex *Box diff --git a/treeview.go b/treeview.go index 50739ed..4fc0325 100644 --- a/treeview.go +++ b/treeview.go @@ -1,4 +1,4 @@ -package tview +package cview import ( "github.com/gdamore/tcell" @@ -238,7 +238,7 @@ func (n *TreeNode) SetIndent(indent int) *TreeNode { // using SetPrefixes() for different levels, for example to display hierarchical // bullet point lists. // -// See https://github.com/rivo/tview/wiki/TreeView for an example. +// See https://git.sr.ht/~tslocum/cview/wiki/TreeView for an example. type TreeView struct { *Box diff --git a/util.go b/util.go index 6c38f55..3dab0e8 100644 --- a/util.go +++ b/util.go @@ -1,4 +1,4 @@ -package tview +package cview import ( "math" @@ -542,8 +542,8 @@ func WordWrap(text string, width int) (lines []string) { // recognized and substituted by the print functions of this package. For // example, to include a tag-like string in a box title or in a TextView: // -// box.SetTitle(tview.Escape("[squarebrackets]")) -// fmt.Fprint(textView, tview.Escape(`["quoted"]`)) +// box.SetTitle(cview.Escape("[squarebrackets]")) +// fmt.Fprint(textView, cview.Escape(`["quoted"]`)) func Escape(text string) string { return nonEscapePattern.ReplaceAllString(text, "$1[]") }