mirror of
https://github.com/Maks1mS/bubbles.git
synced 2025-10-18 16:38:56 +03:00
Compare commits
25 Commits
set-column
...
feature/te
Author | SHA1 | Date | |
---|---|---|---|
5a7d500c9f | |||
6e00038ceb | |||
f7750f3d07 | |||
b1b5a499b7 | |||
0c77bee95d | |||
01abdf10c0 | |||
d40721ef34 | |||
|
fac7a01329 | ||
|
0474e129b8 | ||
|
405c3adc42 | ||
|
85da9addba | ||
|
aea42690e7 | ||
|
9a48dca003 | ||
|
b2b7040ccf | ||
|
d3aed22a41 | ||
|
d177512114 | ||
|
e857875f2a | ||
|
f531ca3055 | ||
|
ea21e3b359 | ||
|
f67537dca5 | ||
|
b7a4a1cd93 | ||
|
4ae575a4c5 | ||
|
bd074d2dbc | ||
|
18909edafc | ||
|
72d87e4513 |
22
.github/dependabot.yml
vendored
Normal file
22
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "gomod"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
||||||
|
time: "08:00"
|
||||||
|
labels:
|
||||||
|
- "dependencies"
|
||||||
|
commit-message:
|
||||||
|
prefix: "feat"
|
||||||
|
include: "scope"
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
||||||
|
time: "08:00"
|
||||||
|
labels:
|
||||||
|
- "dependencies"
|
||||||
|
commit-message:
|
||||||
|
prefix: "chore"
|
||||||
|
include: "scope"
|
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@@ -11,12 +11,12 @@ jobs:
|
|||||||
GO111MODULE: "on"
|
GO111MODULE: "on"
|
||||||
steps:
|
steps:
|
||||||
- name: Install Go
|
- name: Install Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: ${{ matrix.go-version }}
|
go-version: ${{ matrix.go-version }}
|
||||||
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Download Go modules
|
- name: Download Go modules
|
||||||
run: go mod download
|
run: go mod download
|
||||||
|
4
.github/workflows/coverage.yml
vendored
4
.github/workflows/coverage.yml
vendored
@@ -12,12 +12,12 @@ jobs:
|
|||||||
GO111MODULE: "on"
|
GO111MODULE: "on"
|
||||||
steps:
|
steps:
|
||||||
- name: Install Go
|
- name: Install Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: ${{ matrix.go-version }}
|
go-version: ${{ matrix.go-version }}
|
||||||
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Coverage
|
- name: Coverage
|
||||||
env:
|
env:
|
||||||
|
28
.github/workflows/lint-soft.yml
vendored
Normal file
28
.github/workflows/lint-soft.yml
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
name: lint-soft
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
# Optional: allow read access to pull request. Use with `only-new-issues` option.
|
||||||
|
pull-requests: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
golangci:
|
||||||
|
name: lint-soft
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Install Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: ^1
|
||||||
|
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v3
|
||||||
|
with:
|
||||||
|
# Optional: golangci-lint command line arguments.
|
||||||
|
args: --config .golangci-soft.yml --issues-exit-code=0
|
||||||
|
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||||
|
only-new-issues: true
|
22
.github/workflows/lint.yml
vendored
22
.github/workflows/lint.yml
vendored
@@ -1,18 +1,28 @@
|
|||||||
name: lint
|
name: lint
|
||||||
on: [push, pull_request]
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
# Optional: allow read access to pull request. Use with `only-new-issues` option.
|
||||||
|
pull-requests: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
golangci:
|
golangci:
|
||||||
name: lint
|
name: lint
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- name: Install Go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: ^1
|
||||||
|
|
||||||
|
- uses: actions/checkout@v3
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v2
|
uses: golangci/golangci-lint-action@v3
|
||||||
with:
|
with:
|
||||||
# Optional: golangci-lint command line arguments.
|
# Optional: golangci-lint command line arguments.
|
||||||
args: --issues-exit-code=0
|
#args:
|
||||||
# Optional: working directory, useful for monorepos
|
|
||||||
# working-directory: somedir
|
|
||||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||||
only-new-issues: true
|
only-new-issues: true
|
||||||
|
47
.golangci-soft.yml
Normal file
47
.golangci-soft.yml
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
run:
|
||||||
|
tests: false
|
||||||
|
|
||||||
|
issues:
|
||||||
|
include:
|
||||||
|
- EXC0001
|
||||||
|
- EXC0005
|
||||||
|
- EXC0011
|
||||||
|
- EXC0012
|
||||||
|
- EXC0013
|
||||||
|
|
||||||
|
max-issues-per-linter: 0
|
||||||
|
max-same-issues: 0
|
||||||
|
|
||||||
|
linters:
|
||||||
|
enable:
|
||||||
|
# - dupl
|
||||||
|
- exhaustive
|
||||||
|
# - exhaustivestruct
|
||||||
|
- goconst
|
||||||
|
- godot
|
||||||
|
- godox
|
||||||
|
- gomnd
|
||||||
|
- gomoddirectives
|
||||||
|
- goprintffuncname
|
||||||
|
- ifshort
|
||||||
|
# - lll
|
||||||
|
- misspell
|
||||||
|
- nakedret
|
||||||
|
- nestif
|
||||||
|
- noctx
|
||||||
|
- nolintlint
|
||||||
|
- prealloc
|
||||||
|
- wrapcheck
|
||||||
|
|
||||||
|
# disable default linters, they are already enabled in .golangci.yml
|
||||||
|
disable:
|
||||||
|
- deadcode
|
||||||
|
- errcheck
|
||||||
|
- gosimple
|
||||||
|
- govet
|
||||||
|
- ineffassign
|
||||||
|
- staticcheck
|
||||||
|
- structcheck
|
||||||
|
- typecheck
|
||||||
|
- unused
|
||||||
|
- varcheck
|
@@ -15,20 +15,15 @@ issues:
|
|||||||
linters:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
- bodyclose
|
- bodyclose
|
||||||
- dupl
|
|
||||||
- exportloopref
|
- exportloopref
|
||||||
- goconst
|
|
||||||
- godot
|
|
||||||
- godox
|
|
||||||
- goimports
|
- goimports
|
||||||
- goprintffuncname
|
|
||||||
- gosec
|
- gosec
|
||||||
- ifshort
|
- nilerr
|
||||||
- misspell
|
- predeclared
|
||||||
- prealloc
|
|
||||||
- revive
|
- revive
|
||||||
- rowserrcheck
|
- rowserrcheck
|
||||||
- sqlclosecheck
|
- sqlclosecheck
|
||||||
|
- tparallel
|
||||||
- unconvert
|
- unconvert
|
||||||
- unparam
|
- unparam
|
||||||
- whitespace
|
- whitespace
|
||||||
|
34
README.md
34
README.md
@@ -64,11 +64,7 @@ Supports vertical scrolling and many customization options.
|
|||||||
|
|
||||||
## Progress
|
## Progress
|
||||||
|
|
||||||
<picture>
|
<img src="https://stuff.charm.sh/bubbles-examples/progress.gif" width="800" alt="Progressbar Example">
|
||||||
<source media="(max-width: 800px)" srcset="https://stuff.charm.sh/bubbles-examples/progress.gif">
|
|
||||||
<source media="(min-width: 800px)" width="800" srcset="https://stuff.charm.sh/bubbles-examples/progress.gif">
|
|
||||||
<img src="https://stuff.charm.sh/bubbles-examples/progress.gif" alt="Progressbar Example">
|
|
||||||
</picture>
|
|
||||||
|
|
||||||
A simple, customizable progress meter, with optional animation via
|
A simple, customizable progress meter, with optional animation via
|
||||||
[Harmonica][harmonica]. Supports solid and gradient fills. The empty and filled
|
[Harmonica][harmonica]. Supports solid and gradient fills. The empty and filled
|
||||||
@@ -95,11 +91,7 @@ logic and visualize pagination however you like.
|
|||||||
|
|
||||||
## Viewport
|
## Viewport
|
||||||
|
|
||||||
<picture>
|
<img src="https://stuff.charm.sh/bubbles-examples/viewport.gif" width="600" alt="Viewport Example">
|
||||||
<source media="(max-width: 600px)" srcset="https://stuff.charm.sh/bubbles-examples/viewport.gif?0">
|
|
||||||
<source media="(min-width: 600px)" width="600" srcset="https://stuff.charm.sh/bubbles-examples/viewport.gif?0">
|
|
||||||
<img src="https://stuff.charm.sh/bubbles-examples/viewport.gif?0" alt="Viewport Example">
|
|
||||||
</picture>
|
|
||||||
|
|
||||||
A viewport for vertically scrolling content. Optionally includes standard
|
A viewport for vertically scrolling content. Optionally includes standard
|
||||||
pager keybindings and mouse wheel support. A high performance mode is available
|
pager keybindings and mouse wheel support. A high performance mode is available
|
||||||
@@ -115,11 +107,7 @@ indenting and text wrapping.
|
|||||||
|
|
||||||
## List
|
## List
|
||||||
|
|
||||||
<picture>
|
<img src="https://stuff.charm.sh/bubbles-examples/list.gif" width="600" alt="List Example">
|
||||||
<source media="(max-width: 600px)" srcset="https://stuff.charm.sh/bubbles-examples/list.gif">
|
|
||||||
<source media="(min-width: 600px)" width="600" srcset="https://stuff.charm.sh/bubbles-examples/list.gif">
|
|
||||||
<img src="https://stuff.charm.sh/bubbles-examples/list.gif" alt="List Example">
|
|
||||||
</picture>
|
|
||||||
|
|
||||||
A customizable, batteries-included component for browsing a set of items.
|
A customizable, batteries-included component for browsing a set of items.
|
||||||
Features pagination, fuzzy filtering, auto-generated help, an activity spinner,
|
Features pagination, fuzzy filtering, auto-generated help, an activity spinner,
|
||||||
@@ -153,11 +141,7 @@ can be customized as you see fit.
|
|||||||
|
|
||||||
## Help
|
## Help
|
||||||
|
|
||||||
<picture>
|
<img src="https://stuff.charm.sh/bubbles-examples/help.gif" width="500" alt="Help Example">
|
||||||
<source media="(max-width: 500px)" srcset="https://stuff.charm.sh/bubbles-examples/help.gif">
|
|
||||||
<source media="(min-width: 500px)" width="500" srcset="https://stuff.charm.sh/bubbles-examples/help.gif">
|
|
||||||
<img src="https://stuff.charm.sh/bubbles-examples/help.gif" alt="Help Example">
|
|
||||||
</picture>
|
|
||||||
|
|
||||||
A customizable horizontal mini help view that automatically generates itself
|
A customizable horizontal mini help view that automatically generates itself
|
||||||
from your keybindings. It features single and multi-line modes, which the user
|
from your keybindings. It features single and multi-line modes, which the user
|
||||||
@@ -233,12 +217,18 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
If you’ve built a Bubble you think should be listed here,
|
If you’ve built a Bubble you think should be listed here,
|
||||||
[let us know](mailto:vt100@charm.sh).
|
[let us know](mailto:vt100@charm.sh).
|
||||||
|
|
||||||
|
## Feedback
|
||||||
|
|
||||||
|
We’d love to hear your thoughts on this project. Feel free to drop us a note!
|
||||||
|
|
||||||
|
* [Twitter](https://twitter.com/charmcli)
|
||||||
|
* [The Fediverse](https://mastodon.social/@charmcli)
|
||||||
|
* [Discord](https://charm.sh/chat)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
[MIT](https://github.com/charmbracelet/bubbletea/raw/master/LICENSE)
|
[MIT](https://github.com/charmbracelet/bubbletea/raw/master/LICENSE)
|
||||||
|
|
||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
Part of [Charm](https://charm.sh).
|
Part of [Charm](https://charm.sh).
|
||||||
@@ -246,5 +236,3 @@ Part of [Charm](https://charm.sh).
|
|||||||
<a href="https://charm.sh/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-badge.jpg" width="400"></a>
|
<a href="https://charm.sh/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-badge.jpg" width="400"></a>
|
||||||
|
|
||||||
Charm热爱开源 • Charm loves open source
|
Charm热爱开源 • Charm loves open source
|
||||||
|
|
||||||
[charm]: https://charm.sh/
|
|
||||||
|
8
go.mod
8
go.mod
@@ -1,15 +1,15 @@
|
|||||||
module github.com/charmbracelet/bubbles
|
module github.com/Maks1mS/bubbles
|
||||||
|
|
||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/atotto/clipboard v0.1.4
|
github.com/atotto/clipboard v0.1.4
|
||||||
github.com/charmbracelet/bubbletea v0.21.0
|
github.com/charmbracelet/bubbletea v0.22.1
|
||||||
github.com/charmbracelet/harmonica v0.2.0
|
github.com/charmbracelet/harmonica v0.2.0
|
||||||
github.com/charmbracelet/lipgloss v0.5.0
|
github.com/charmbracelet/lipgloss v0.6.0
|
||||||
github.com/kylelemons/godebug v1.1.0 // indirect
|
github.com/kylelemons/godebug v1.1.0 // indirect
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0
|
github.com/lucasb-eyer/go-colorful v1.2.0
|
||||||
github.com/mattn/go-runewidth v0.0.13
|
github.com/mattn/go-runewidth v0.0.14
|
||||||
github.com/muesli/reflow v0.3.0
|
github.com/muesli/reflow v0.3.0
|
||||||
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739
|
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739
|
||||||
github.com/sahilm/fuzzy v0.1.0
|
github.com/sahilm/fuzzy v0.1.0
|
||||||
|
30
go.sum
30
go.sum
@@ -1,27 +1,31 @@
|
|||||||
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
||||||
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
||||||
github.com/charmbracelet/bubbletea v0.21.0 h1:f3y+kanzgev5PA916qxmDybSHU3N804uOnKnhRPXTcI=
|
github.com/charmbracelet/bubbletea v0.22.1 h1:z66q0LWdJNOWEH9zadiAIXp2GN1AWrwNXU8obVY9X24=
|
||||||
github.com/charmbracelet/bubbletea v0.21.0/go.mod h1:GgmJMec61d08zXsOhqRC/AiOx4K4pmz+VIcRIm1FKr4=
|
github.com/charmbracelet/bubbletea v0.22.1/go.mod h1:8/7hVvbPN6ZZPkczLiB8YpLkLJ0n7DMho5Wvfd2X1C0=
|
||||||
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
|
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
|
||||||
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
|
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
|
||||||
github.com/charmbracelet/lipgloss v0.5.0 h1:lulQHuVeodSgDez+3rGiuxlPVXSnhth442DATR2/8t8=
|
github.com/charmbracelet/lipgloss v0.6.0 h1:1StyZB9vBSOyuZxQUcUwGr17JmojPNm87inij9N3wJY=
|
||||||
github.com/charmbracelet/lipgloss v0.5.0/go.mod h1:EZLha/HbzEt7cYqdFPovlqy5FZPj0xFhg5SaqxScmgs=
|
github.com/charmbracelet/lipgloss v0.6.0/go.mod h1:tHh2wr34xcHjC2HCXIlGSG1jaDF0S0atAUvBMP6Ppuk=
|
||||||
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
|
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
|
||||||
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
|
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
|
||||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
|
||||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||||
|
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
|
||||||
|
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
|
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
|
||||||
|
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
|
||||||
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||||
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
||||||
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
|
|
||||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
|
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
|
||||||
|
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
|
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
|
||||||
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
|
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
|
||||||
github.com/muesli/cancelreader v0.2.0 h1:SOpr+CfyVNce341kKqvbhhzQhBPyJRXQaCtn03Pae1Q=
|
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
||||||
github.com/muesli/cancelreader v0.2.0/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
||||||
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
|
github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
|
||||||
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
|
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
|
||||||
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
|
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
|
||||||
@@ -29,10 +33,7 @@ github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0/go.mod h1:Bd5NYQ
|
|||||||
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 h1:QANkGiGr39l1EESqrE0gZw0/AJNYzIvoGLhIoVYtluI=
|
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 h1:QANkGiGr39l1EESqrE0gZw0/AJNYzIvoGLhIoVYtluI=
|
||||||
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
|
github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
|
||||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
|
||||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
|
||||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
|
||||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI=
|
github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI=
|
||||||
github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
|
github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
|
||||||
@@ -40,7 +41,10 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
|
||||||
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
@@ -3,7 +3,7 @@ package help
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/key"
|
"github.com/Maks1mS/bubbles/key"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
)
|
)
|
||||||
@@ -203,7 +203,7 @@ func (m Model) FullHelpView(groups [][]key.Binding) string {
|
|||||||
|
|
||||||
// Column
|
// Column
|
||||||
totalWidth += lipgloss.Width(col)
|
totalWidth += lipgloss.Width(col)
|
||||||
if totalWidth > m.Width {
|
if m.Width > 0 && totalWidth > m.Width {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ func (m Model) FullHelpView(groups [][]key.Binding) string {
|
|||||||
// Separator
|
// Separator
|
||||||
if i < len(group)-1 {
|
if i < len(group)-1 {
|
||||||
totalWidth += sepWidth
|
totalWidth += sepWidth
|
||||||
if totalWidth > m.Width {
|
if m.Width > 0 && totalWidth > m.Width {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
52
key/key.go
52
key/key.go
@@ -2,35 +2,35 @@
|
|||||||
// keymappings useful in Bubble Tea components. There are a few different ways
|
// keymappings useful in Bubble Tea components. There are a few different ways
|
||||||
// you can define a keymapping with this package. Here's one example:
|
// you can define a keymapping with this package. Here's one example:
|
||||||
//
|
//
|
||||||
// type KeyMap struct {
|
// type KeyMap struct {
|
||||||
// Up key.Binding
|
// Up key.Binding
|
||||||
// Down key.Binding
|
// Down key.Binding
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// var DefaultKeyMap = KeyMap{
|
// var DefaultKeyMap = KeyMap{
|
||||||
// Up: key.NewBinding(
|
// Up: key.NewBinding(
|
||||||
// key.WithKeys("k", "up"), // actual keybindings
|
// key.WithKeys("k", "up"), // actual keybindings
|
||||||
// key.WithHelp("↑/k", "move up"), // corresponding help text
|
// key.WithHelp("↑/k", "move up"), // corresponding help text
|
||||||
// ),
|
// ),
|
||||||
// Down: key.NewBinding(
|
// Down: key.NewBinding(
|
||||||
// key.WithKeys("j", "down"),
|
// key.WithKeys("j", "down"),
|
||||||
// key.WithHelp("↓/j", "move down"),
|
// key.WithHelp("↓/j", "move down"),
|
||||||
// ),
|
// ),
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
// func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
// switch msg := msg.(type) {
|
// switch msg := msg.(type) {
|
||||||
// case tea.KeyMsg:
|
// case tea.KeyMsg:
|
||||||
// switch {
|
// switch {
|
||||||
// case key.Matches(msg, DefaultKeyMap.Up):
|
// case key.Matches(msg, DefaultKeyMap.Up):
|
||||||
// // The user pressed up
|
// // The user pressed up
|
||||||
// case key.Matches(msg, DefaultKeyMap.Down):
|
// case key.Matches(msg, DefaultKeyMap.Down):
|
||||||
// // The user pressed down
|
// // The user pressed down
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// // ...
|
// // ...
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// The help information, which is not used in the example above, can be used
|
// The help information, which is not used in the example above, can be used
|
||||||
// to render help text for keystrokes in your views.
|
// to render help text for keystrokes in your views.
|
||||||
|
@@ -5,7 +5,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/key"
|
"github.com/Maks1mS/bubbles/key"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/muesli/reflow/truncate"
|
"github.com/muesli/reflow/truncate"
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
package list
|
package list
|
||||||
|
|
||||||
import "github.com/charmbracelet/bubbles/key"
|
import "github.com/Maks1mS/bubbles/key"
|
||||||
|
|
||||||
// KeyMap defines keybindings. It satisfies to the help.KeyMap interface, which
|
// KeyMap defines keybindings. It satisfies to the help.KeyMap interface, which
|
||||||
// is used to render the menu menu.
|
// is used to render the menu menu.
|
||||||
|
23
list/list.go
23
list/list.go
@@ -10,11 +10,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/help"
|
"github.com/Maks1mS/bubbles/help"
|
||||||
"github.com/charmbracelet/bubbles/key"
|
"github.com/Maks1mS/bubbles/key"
|
||||||
"github.com/charmbracelet/bubbles/paginator"
|
"github.com/Maks1mS/bubbles/paginator"
|
||||||
"github.com/charmbracelet/bubbles/spinner"
|
"github.com/Maks1mS/bubbles/spinner"
|
||||||
"github.com/charmbracelet/bubbles/textinput"
|
"github.com/Maks1mS/bubbles/textinput"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/muesli/reflow/ansi"
|
"github.com/muesli/reflow/ansi"
|
||||||
@@ -183,18 +183,18 @@ type Model struct {
|
|||||||
func New(items []Item, delegate ItemDelegate, width, height int) Model {
|
func New(items []Item, delegate ItemDelegate, width, height int) Model {
|
||||||
styles := DefaultStyles()
|
styles := DefaultStyles()
|
||||||
|
|
||||||
sp := spinner.NewModel()
|
sp := spinner.New()
|
||||||
sp.Spinner = spinner.Line
|
sp.Spinner = spinner.Line
|
||||||
sp.Style = styles.Spinner
|
sp.Style = styles.Spinner
|
||||||
|
|
||||||
filterInput := textinput.NewModel()
|
filterInput := textinput.New()
|
||||||
filterInput.Prompt = "Filter: "
|
filterInput.Prompt = "Filter: "
|
||||||
filterInput.PromptStyle = styles.FilterPrompt
|
filterInput.PromptStyle = styles.FilterPrompt
|
||||||
filterInput.CursorStyle = styles.FilterCursor
|
filterInput.CursorStyle = styles.FilterCursor
|
||||||
filterInput.CharLimit = 64
|
filterInput.CharLimit = 64
|
||||||
filterInput.Focus()
|
filterInput.Focus()
|
||||||
|
|
||||||
p := paginator.NewModel()
|
p := paginator.New()
|
||||||
p.Type = paginator.Dots
|
p.Type = paginator.Dots
|
||||||
p.ActiveDot = styles.ActivePaginationDot.String()
|
p.ActiveDot = styles.ActivePaginationDot.String()
|
||||||
p.InactiveDot = styles.InactivePaginationDot.String()
|
p.InactiveDot = styles.InactivePaginationDot.String()
|
||||||
@@ -221,7 +221,7 @@ func New(items []Item, delegate ItemDelegate, width, height int) Model {
|
|||||||
items: items,
|
items: items,
|
||||||
Paginator: p,
|
Paginator: p,
|
||||||
spinner: sp,
|
spinner: sp,
|
||||||
Help: help.NewModel(),
|
Help: help.New(),
|
||||||
}
|
}
|
||||||
|
|
||||||
m.updatePagination()
|
m.updatePagination()
|
||||||
@@ -526,7 +526,7 @@ func (m Model) FilterValue() string {
|
|||||||
// SettingFilter returns whether or not the user is currently editing the
|
// SettingFilter returns whether or not the user is currently editing the
|
||||||
// filter value. It's purely a convenience method for the following:
|
// filter value. It's purely a convenience method for the following:
|
||||||
//
|
//
|
||||||
// m.FilterState() == Filtering
|
// m.FilterState() == Filtering
|
||||||
//
|
//
|
||||||
// It's included here because it's a common thing to check for when
|
// It's included here because it's a common thing to check for when
|
||||||
// implementing this component.
|
// implementing this component.
|
||||||
@@ -537,8 +537,7 @@ func (m Model) SettingFilter() bool {
|
|||||||
// IsFiltered returns whether or not the list is currently filtered.
|
// IsFiltered returns whether or not the list is currently filtered.
|
||||||
// It's purely a convenience method for the following:
|
// It's purely a convenience method for the following:
|
||||||
//
|
//
|
||||||
// m.FilterState() == FilterApplied
|
// m.FilterState() == FilterApplied
|
||||||
//
|
|
||||||
func (m Model) IsFiltered() bool {
|
func (m Model) IsFiltered() bool {
|
||||||
return m.filterState == FilterApplied
|
return m.filterState == FilterApplied
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,7 @@ package paginator
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/Maks1mS/bubbles/key"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,20 +20,49 @@ const (
|
|||||||
Dots
|
Dots
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// KeyMap is the key bindings for different actions within the paginator.
|
||||||
|
type KeyMap struct {
|
||||||
|
PrevPage key.Binding
|
||||||
|
NextPage key.Binding
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefaultKeyMap is the default set of key bindings for navigating and acting
|
||||||
|
// upon the paginator.
|
||||||
|
var DefaultKeyMap = KeyMap{
|
||||||
|
PrevPage: key.NewBinding(key.WithKeys("pgup", "left", "h")),
|
||||||
|
NextPage: key.NewBinding(key.WithKeys("pgdown", "right", "l")),
|
||||||
|
}
|
||||||
|
|
||||||
// Model is the Bubble Tea model for this user interface.
|
// Model is the Bubble Tea model for this user interface.
|
||||||
type Model struct {
|
type Model struct {
|
||||||
Type Type
|
// Type configures how the pagination is rendered (Arabic, Dots).
|
||||||
Page int
|
Type Type
|
||||||
PerPage int
|
// Page is the current page number.
|
||||||
TotalPages int
|
Page int
|
||||||
ActiveDot string
|
// PerPage is the number of items per page.
|
||||||
InactiveDot string
|
PerPage int
|
||||||
ArabicFormat string
|
// TotalPages is the total number of pages.
|
||||||
|
TotalPages int
|
||||||
|
// ActiveDot is used to mark the current page under the Dots display type.
|
||||||
|
ActiveDot string
|
||||||
|
// InactiveDot is used to mark inactive pages under the Dots display type.
|
||||||
|
InactiveDot string
|
||||||
|
// ArabicFormat is the printf-style format to use for the Arabic display type.
|
||||||
|
ArabicFormat string
|
||||||
|
|
||||||
|
// KeyMap encodes the keybindings recognized by the widget.
|
||||||
|
KeyMap KeyMap
|
||||||
|
|
||||||
|
// Deprecated: customize KeyMap instead.
|
||||||
UsePgUpPgDownKeys bool
|
UsePgUpPgDownKeys bool
|
||||||
UseLeftRightKeys bool
|
// Deprecated: customize KeyMap instead.
|
||||||
UseUpDownKeys bool
|
UseLeftRightKeys bool
|
||||||
UseHLKeys bool
|
// Deprecated: customize KeyMap instead.
|
||||||
UseJKKeys bool
|
UseUpDownKeys bool
|
||||||
|
// Deprecated: customize KeyMap instead.
|
||||||
|
UseHLKeys bool
|
||||||
|
// Deprecated: customize KeyMap instead.
|
||||||
|
UseJKKeys bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTotalPages is a helper function for calculating the total number of pages
|
// SetTotalPages is a helper function for calculating the total number of pages
|
||||||
@@ -65,10 +95,9 @@ func (m Model) ItemsOnPage(totalItems int) int {
|
|||||||
// of the slice you're rendering and you'll receive the start and end bounds
|
// of the slice you're rendering and you'll receive the start and end bounds
|
||||||
// corresponding the to pagination. For example:
|
// corresponding the to pagination. For example:
|
||||||
//
|
//
|
||||||
// bunchOfStuff := []stuff{...}
|
// bunchOfStuff := []stuff{...}
|
||||||
// start, end := model.GetSliceBounds(len(bunchOfStuff))
|
// start, end := model.GetSliceBounds(len(bunchOfStuff))
|
||||||
// sliceToRender := bunchOfStuff[start:end]
|
// sliceToRender := bunchOfStuff[start:end]
|
||||||
//
|
|
||||||
func (m *Model) GetSliceBounds(length int) (start int, end int) {
|
func (m *Model) GetSliceBounds(length int) (start int, end int) {
|
||||||
start = m.Page * m.PerPage
|
start = m.Page * m.PerPage
|
||||||
end = min(m.Page*m.PerPage+m.PerPage, length)
|
end = min(m.Page*m.PerPage+m.PerPage, length)
|
||||||
@@ -99,18 +128,14 @@ func (m Model) OnLastPage() bool {
|
|||||||
// New creates a new model with defaults.
|
// New creates a new model with defaults.
|
||||||
func New() Model {
|
func New() Model {
|
||||||
return Model{
|
return Model{
|
||||||
Type: Arabic,
|
Type: Arabic,
|
||||||
Page: 0,
|
Page: 0,
|
||||||
PerPage: 1,
|
PerPage: 1,
|
||||||
TotalPages: 1,
|
TotalPages: 1,
|
||||||
ActiveDot: "•",
|
KeyMap: DefaultKeyMap,
|
||||||
InactiveDot: "○",
|
ActiveDot: "•",
|
||||||
ArabicFormat: "%d/%d",
|
InactiveDot: "○",
|
||||||
UsePgUpPgDownKeys: true,
|
ArabicFormat: "%d/%d",
|
||||||
UseLeftRightKeys: true,
|
|
||||||
UseUpDownKeys: false,
|
|
||||||
UseHLKeys: true,
|
|
||||||
UseJKKeys: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,45 +148,11 @@ var NewModel = New
|
|||||||
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
if m.UsePgUpPgDownKeys {
|
switch {
|
||||||
switch msg.String() {
|
case key.Matches(msg, m.KeyMap.NextPage):
|
||||||
case "pgup":
|
m.NextPage()
|
||||||
m.PrevPage()
|
case key.Matches(msg, m.KeyMap.PrevPage):
|
||||||
case "pgdown":
|
m.PrevPage()
|
||||||
m.NextPage()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if m.UseLeftRightKeys {
|
|
||||||
switch msg.String() {
|
|
||||||
case "left":
|
|
||||||
m.PrevPage()
|
|
||||||
case "right":
|
|
||||||
m.NextPage()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if m.UseUpDownKeys {
|
|
||||||
switch msg.String() {
|
|
||||||
case "up":
|
|
||||||
m.PrevPage()
|
|
||||||
case "down":
|
|
||||||
m.NextPage()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if m.UseHLKeys {
|
|
||||||
switch msg.String() {
|
|
||||||
case "h":
|
|
||||||
m.PrevPage()
|
|
||||||
case "l":
|
|
||||||
m.NextPage()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if m.UseJKKeys {
|
|
||||||
switch msg.String() {
|
|
||||||
case "j":
|
|
||||||
m.PrevPage()
|
|
||||||
case "k":
|
|
||||||
m.NextPage()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,13 +37,12 @@ const (
|
|||||||
defaultDamping = 1.0
|
defaultDamping = 1.0
|
||||||
)
|
)
|
||||||
|
|
||||||
// Option is used to set options in NewModel. For example:
|
// Option is used to set options in New. For example:
|
||||||
//
|
|
||||||
// progress := NewModel(
|
|
||||||
// WithRamp("#ff0000", "#0000ff"),
|
|
||||||
// WithoutPercentage(),
|
|
||||||
// )
|
|
||||||
//
|
//
|
||||||
|
// progress := New(
|
||||||
|
// WithRamp("#ff0000", "#0000ff"),
|
||||||
|
// WithoutPercentage(),
|
||||||
|
// )
|
||||||
type Option func(*Model)
|
type Option func(*Model)
|
||||||
|
|
||||||
// WithDefaultGradient sets a gradient fill with default colors.
|
// WithDefaultGradient sets a gradient fill with default colors.
|
||||||
|
@@ -85,7 +85,7 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Model contains the state for the spinner. Use NewModel to create new models
|
// Model contains the state for the spinner. Use New to create new models
|
||||||
// rather than using Model as a struct literal.
|
// rather than using Model as a struct literal.
|
||||||
type Model struct {
|
type Model struct {
|
||||||
// Spinner settings to use. See type Spinner.
|
// Spinner settings to use. See type Spinner.
|
||||||
@@ -208,8 +208,7 @@ func Tick() tea.Msg {
|
|||||||
|
|
||||||
// Option is used to set options in New. For example:
|
// Option is used to set options in New. For example:
|
||||||
//
|
//
|
||||||
// spinner := New(WithSpinner(Dot))
|
// spinner := New(WithSpinner(Dot))
|
||||||
//
|
|
||||||
type Option func(*Model)
|
type Option func(*Model)
|
||||||
|
|
||||||
// WithSpinner is an option to set the spinner.
|
// WithSpinner is an option to set the spinner.
|
||||||
|
@@ -3,7 +3,7 @@ package spinner_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/spinner"
|
"github.com/Maks1mS/bubbles/spinner"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSpinnerNew(t *testing.T) {
|
func TestSpinnerNew(t *testing.T) {
|
||||||
|
@@ -3,8 +3,8 @@ package table
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/key"
|
"github.com/Maks1mS/bubbles/key"
|
||||||
"github.com/charmbracelet/bubbles/viewport"
|
"github.com/Maks1mS/bubbles/viewport"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/mattn/go-runewidth"
|
"github.com/mattn/go-runewidth"
|
||||||
@@ -109,8 +109,7 @@ func (m *Model) SetStyles(s Styles) {
|
|||||||
|
|
||||||
// Option is used to set options in New. For example:
|
// Option is used to set options in New. For example:
|
||||||
//
|
//
|
||||||
// table := New(WithColumns([]Column{{Title: "ID", Width: 10}}))
|
// table := New(WithColumns([]Column{{Title: "ID", Width: 10}}))
|
||||||
//
|
|
||||||
type Option func(*Model)
|
type Option func(*Model)
|
||||||
|
|
||||||
// New creates a new model for the table widget.
|
// New creates a new model for the table widget.
|
||||||
|
@@ -5,10 +5,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/Maks1mS/bubbles/cursor"
|
||||||
|
"github.com/Maks1mS/bubbles/key"
|
||||||
|
"github.com/Maks1mS/bubbles/viewport"
|
||||||
"github.com/atotto/clipboard"
|
"github.com/atotto/clipboard"
|
||||||
"github.com/charmbracelet/bubbles/internal/cursor"
|
|
||||||
"github.com/charmbracelet/bubbles/key"
|
|
||||||
"github.com/charmbracelet/bubbles/viewport"
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
rw "github.com/mattn/go-runewidth"
|
rw "github.com/mattn/go-runewidth"
|
||||||
@@ -212,6 +212,8 @@ type Model struct {
|
|||||||
// viewport is the vertically-scrollable viewport of the multi-line text
|
// viewport is the vertically-scrollable viewport of the multi-line text
|
||||||
// input.
|
// input.
|
||||||
viewport *viewport.Model
|
viewport *viewport.Model
|
||||||
|
|
||||||
|
isChanged bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new model with default settings.
|
// New creates a new model with default settings.
|
||||||
@@ -281,6 +283,12 @@ func (m *Model) SetValue(s string) {
|
|||||||
m.InsertString(s)
|
m.InsertString(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Model) SetValueAndReset(s string) {
|
||||||
|
m.Reset()
|
||||||
|
m.InsertString(s)
|
||||||
|
m.ResetWithoutValue()
|
||||||
|
}
|
||||||
|
|
||||||
// InsertString inserts a string at the cursor position.
|
// InsertString inserts a string at the cursor position.
|
||||||
func (m *Model) InsertString(s string) {
|
func (m *Model) InsertString(s string) {
|
||||||
lines := strings.Split(s, "\n")
|
lines := strings.Split(s, "\n")
|
||||||
@@ -320,6 +328,10 @@ func (m Model) Value() string {
|
|||||||
return strings.TrimSuffix(v.String(), "\n")
|
return strings.TrimSuffix(v.String(), "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Model) IsChanged() bool {
|
||||||
|
return m.isChanged
|
||||||
|
}
|
||||||
|
|
||||||
// Length returns the number of characters currently in the text input.
|
// Length returns the number of characters currently in the text input.
|
||||||
func (m *Model) Length() int {
|
func (m *Model) Length() int {
|
||||||
var l int
|
var l int
|
||||||
@@ -450,12 +462,25 @@ func (m *Model) Blur() {
|
|||||||
// Reset sets the input to its default state with no input.
|
// Reset sets the input to its default state with no input.
|
||||||
func (m *Model) Reset() {
|
func (m *Model) Reset() {
|
||||||
m.value = make([][]rune, minHeight, maxHeight)
|
m.value = make([][]rune, minHeight, maxHeight)
|
||||||
|
m.ResetWithoutValue()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Model) ResetWithoutValue() {
|
||||||
|
m.ResetView()
|
||||||
|
m.ResetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Model) ResetView() {
|
||||||
m.col = 0
|
m.col = 0
|
||||||
m.row = 0
|
m.row = 0
|
||||||
m.viewport.GotoTop()
|
m.viewport.GotoTop()
|
||||||
m.SetCursor(0)
|
m.SetCursor(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Model) ResetChanged() {
|
||||||
|
m.isChanged = false
|
||||||
|
}
|
||||||
|
|
||||||
// handle a clipboard paste event, if supported.
|
// handle a clipboard paste event, if supported.
|
||||||
func (m *Model) handlePaste(v string) {
|
func (m *Model) handlePaste(v string) {
|
||||||
paste := []rune(v)
|
paste := []rune(v)
|
||||||
@@ -494,6 +519,11 @@ func (m *Model) handlePaste(v string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Put it all back together
|
||||||
|
value := append(head, tail...)
|
||||||
|
m.SetValue(string(value))
|
||||||
|
m.isChanged = true
|
||||||
|
|
||||||
// Reset blink state if necessary and run overflow checks
|
// Reset blink state if necessary and run overflow checks
|
||||||
m.SetCursor(m.col + len(paste))
|
m.SetCursor(m.col + len(paste))
|
||||||
}
|
}
|
||||||
@@ -502,6 +532,7 @@ func (m *Model) handlePaste(v string) {
|
|||||||
// not the cursor blink should be reset.
|
// not the cursor blink should be reset.
|
||||||
func (m *Model) deleteBeforeCursor() {
|
func (m *Model) deleteBeforeCursor() {
|
||||||
m.value[m.row] = m.value[m.row][m.col:]
|
m.value[m.row] = m.value[m.row][m.col:]
|
||||||
|
m.isChanged = true
|
||||||
m.SetCursor(0)
|
m.SetCursor(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,6 +541,7 @@ func (m *Model) deleteBeforeCursor() {
|
|||||||
// the cursor so as not to reveal word breaks in the masked input.
|
// the cursor so as not to reveal word breaks in the masked input.
|
||||||
func (m *Model) deleteAfterCursor() {
|
func (m *Model) deleteAfterCursor() {
|
||||||
m.value[m.row] = m.value[m.row][:m.col]
|
m.value[m.row] = m.value[m.row][:m.col]
|
||||||
|
m.isChanged = true
|
||||||
m.SetCursor(len(m.value[m.row]))
|
m.SetCursor(len(m.value[m.row]))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -529,6 +561,7 @@ func (m *Model) transposeLeft() {
|
|||||||
if m.col < len(m.value[m.row]) {
|
if m.col < len(m.value[m.row]) {
|
||||||
m.SetCursor(m.col + 1)
|
m.SetCursor(m.col + 1)
|
||||||
}
|
}
|
||||||
|
m.isChanged = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// deleteWordLeft deletes the word left to the cursor. Returns whether or not
|
// deleteWordLeft deletes the word left to the cursor. Returns whether or not
|
||||||
@@ -569,6 +602,8 @@ func (m *Model) deleteWordLeft() {
|
|||||||
} else {
|
} else {
|
||||||
m.value[m.row] = append(m.value[m.row][:m.col], m.value[m.row][oldCol:]...)
|
m.value[m.row] = append(m.value[m.row][:m.col], m.value[m.row][oldCol:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.isChanged = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// deleteWordRight deletes the word right to the cursor.
|
// deleteWordRight deletes the word right to the cursor.
|
||||||
@@ -603,6 +638,7 @@ func (m *Model) deleteWordRight() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.SetCursor(oldCol)
|
m.SetCursor(oldCol)
|
||||||
|
m.isChanged = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// characterRight moves the cursor one character to the right.
|
// characterRight moves the cursor one character to the right.
|
||||||
@@ -688,6 +724,7 @@ func (m *Model) uppercaseRight() {
|
|||||||
m.doWordRight(func(_ int, i int) {
|
m.doWordRight(func(_ int, i int) {
|
||||||
m.value[m.row][i] = unicode.ToUpper(m.value[m.row][i])
|
m.value[m.row][i] = unicode.ToUpper(m.value[m.row][i])
|
||||||
})
|
})
|
||||||
|
m.isChanged = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// lowercaseRight changes the word to the right to lowercase.
|
// lowercaseRight changes the word to the right to lowercase.
|
||||||
@@ -695,6 +732,7 @@ func (m *Model) lowercaseRight() {
|
|||||||
m.doWordRight(func(_ int, i int) {
|
m.doWordRight(func(_ int, i int) {
|
||||||
m.value[m.row][i] = unicode.ToLower(m.value[m.row][i])
|
m.value[m.row][i] = unicode.ToLower(m.value[m.row][i])
|
||||||
})
|
})
|
||||||
|
m.isChanged = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// capitalizeRight changes the word to the right to title case.
|
// capitalizeRight changes the word to the right to title case.
|
||||||
@@ -704,6 +742,7 @@ func (m *Model) capitalizeRight() {
|
|||||||
m.value[m.row][i] = unicode.ToTitle(m.value[m.row][i])
|
m.value[m.row][i] = unicode.ToTitle(m.value[m.row][i])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
m.isChanged = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// LineInfo returns the number of characters from the start of the
|
// LineInfo returns the number of characters from the start of the
|
||||||
@@ -869,6 +908,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
if len(m.value[m.row]) > 0 {
|
if len(m.value[m.row]) > 0 {
|
||||||
m.value[m.row] = append(m.value[m.row][:max(0, m.col-1)], m.value[m.row][m.col:]...)
|
m.value[m.row] = append(m.value[m.row][:max(0, m.col-1)], m.value[m.row][m.col:]...)
|
||||||
|
m.isChanged = true
|
||||||
if m.col > 0 {
|
if m.col > 0 {
|
||||||
m.SetCursor(m.col - 1)
|
m.SetCursor(m.col - 1)
|
||||||
}
|
}
|
||||||
@@ -876,6 +916,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
|||||||
case key.Matches(msg, m.KeyMap.DeleteCharacterForward):
|
case key.Matches(msg, m.KeyMap.DeleteCharacterForward):
|
||||||
if len(m.value[m.row]) > 0 && m.col < len(m.value[m.row]) {
|
if len(m.value[m.row]) > 0 && m.col < len(m.value[m.row]) {
|
||||||
m.value[m.row] = append(m.value[m.row][:m.col], m.value[m.row][m.col+1:]...)
|
m.value[m.row] = append(m.value[m.row][:m.col], m.value[m.row][m.col+1:]...)
|
||||||
|
m.isChanged = true
|
||||||
}
|
}
|
||||||
if m.col >= len(m.value[m.row]) {
|
if m.col >= len(m.value[m.row]) {
|
||||||
m.mergeLineBelow(m.row)
|
m.mergeLineBelow(m.row)
|
||||||
@@ -938,6 +979,7 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
|||||||
|
|
||||||
m.col = min(m.col, len(m.value[m.row]))
|
m.col = min(m.col, len(m.value[m.row]))
|
||||||
m.value[m.row] = append(m.value[m.row][:m.col], append(msg.Runes, m.value[m.row][m.col:]...)...)
|
m.value[m.row] = append(m.value[m.row][:m.col], append(msg.Runes, m.value[m.row][m.col:]...)...)
|
||||||
|
m.isChanged = true
|
||||||
m.SetCursor(m.col + len(msg.Runes))
|
m.SetCursor(m.col + len(msg.Runes))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1146,6 +1188,8 @@ func (m *Model) mergeLineBelow(row int) {
|
|||||||
if len(m.value) > 0 {
|
if len(m.value) > 0 {
|
||||||
m.value = m.value[:len(m.value)-1]
|
m.value = m.value[:len(m.value)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.isChanged = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// mergeLineAbove merges the current line the cursor is on with the line above.
|
// mergeLineAbove merges the current line the cursor is on with the line above.
|
||||||
@@ -1169,6 +1213,8 @@ func (m *Model) mergeLineAbove(row int) {
|
|||||||
if len(m.value) > 0 {
|
if len(m.value) > 0 {
|
||||||
m.value = m.value[:len(m.value)-1]
|
m.value = m.value[:len(m.value)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.isChanged = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) splitLine(row, col int) {
|
func (m *Model) splitLine(row, col int) {
|
||||||
@@ -1186,6 +1232,8 @@ func (m *Model) splitLine(row, col int) {
|
|||||||
|
|
||||||
m.col = 0
|
m.col = 0
|
||||||
m.row++
|
m.row++
|
||||||
|
|
||||||
|
m.isChanged = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Paste is a command for pasting from the clipboard into the text input.
|
// Paste is a command for pasting from the clipboard into the text input.
|
||||||
|
@@ -5,8 +5,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/Maks1mS/bubbles/cursor"
|
||||||
|
"github.com/Maks1mS/bubbles/key"
|
||||||
"github.com/atotto/clipboard"
|
"github.com/atotto/clipboard"
|
||||||
"github.com/charmbracelet/bubbles/internal/cursor"
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
rw "github.com/mattn/go-runewidth"
|
rw "github.com/mattn/go-runewidth"
|
||||||
@@ -37,6 +38,41 @@ const (
|
|||||||
// ValidateFunc is a function that returns an error if the input is invalid.
|
// ValidateFunc is a function that returns an error if the input is invalid.
|
||||||
type ValidateFunc func(string) error
|
type ValidateFunc func(string) error
|
||||||
|
|
||||||
|
// KeyMap is the key bindings for different actions within the textinput.
|
||||||
|
type KeyMap struct {
|
||||||
|
CharacterForward key.Binding
|
||||||
|
CharacterBackward key.Binding
|
||||||
|
WordForward key.Binding
|
||||||
|
WordBackward key.Binding
|
||||||
|
DeleteWordBackward key.Binding
|
||||||
|
DeleteWordForward key.Binding
|
||||||
|
DeleteAfterCursor key.Binding
|
||||||
|
DeleteBeforeCursor key.Binding
|
||||||
|
DeleteCharacterBackward key.Binding
|
||||||
|
DeleteCharacterForward key.Binding
|
||||||
|
LineStart key.Binding
|
||||||
|
LineEnd key.Binding
|
||||||
|
Paste key.Binding
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefaultKeyMap is the default set of key bindings for navigating and acting
|
||||||
|
// upon the textinput.
|
||||||
|
var DefaultKeyMap = KeyMap{
|
||||||
|
CharacterForward: key.NewBinding(key.WithKeys("right", "ctrl+f")),
|
||||||
|
CharacterBackward: key.NewBinding(key.WithKeys("left", "ctrl+b")),
|
||||||
|
WordForward: key.NewBinding(key.WithKeys("alt+right", "alt+f")),
|
||||||
|
WordBackward: key.NewBinding(key.WithKeys("alt+left", "alt+b")),
|
||||||
|
DeleteWordBackward: key.NewBinding(key.WithKeys("alt+backspace", "ctrl+w")),
|
||||||
|
DeleteWordForward: key.NewBinding(key.WithKeys("alte+delete", "alt+d")),
|
||||||
|
DeleteAfterCursor: key.NewBinding(key.WithKeys("ctrl+k")),
|
||||||
|
DeleteBeforeCursor: key.NewBinding(key.WithKeys("ctrl+u")),
|
||||||
|
DeleteCharacterBackward: key.NewBinding(key.WithKeys("backspace", "ctrl+h")),
|
||||||
|
DeleteCharacterForward: key.NewBinding(key.WithKeys("delete", "ctrl+d")),
|
||||||
|
LineStart: key.NewBinding(key.WithKeys("home", "ctrl+a")),
|
||||||
|
LineEnd: key.NewBinding(key.WithKeys("end", "ctrl+e")),
|
||||||
|
Paste: key.NewBinding(key.WithKeys("ctrl+v")),
|
||||||
|
}
|
||||||
|
|
||||||
// Model is the Bubble Tea model for this text input element.
|
// Model is the Bubble Tea model for this text input element.
|
||||||
type Model struct {
|
type Model struct {
|
||||||
Err error
|
Err error
|
||||||
@@ -71,6 +107,9 @@ type Model struct {
|
|||||||
// viewport. If 0 or less this setting is ignored.
|
// viewport. If 0 or less this setting is ignored.
|
||||||
Width int
|
Width int
|
||||||
|
|
||||||
|
// KeyMap encodes the keybindings recognized by the widget.
|
||||||
|
KeyMap KeyMap
|
||||||
|
|
||||||
// Underlying text value.
|
// Underlying text value.
|
||||||
value []rune
|
value []rune
|
||||||
|
|
||||||
@@ -101,6 +140,7 @@ func New() Model {
|
|||||||
CharLimit: 0,
|
CharLimit: 0,
|
||||||
PlaceholderStyle: lipgloss.NewStyle().Foreground(lipgloss.Color("240")),
|
PlaceholderStyle: lipgloss.NewStyle().Foreground(lipgloss.Color("240")),
|
||||||
Cursor: cursor.New(),
|
Cursor: cursor.New(),
|
||||||
|
KeyMap: DefaultKeyMap,
|
||||||
|
|
||||||
value: nil,
|
value: nil,
|
||||||
focus: false,
|
focus: false,
|
||||||
@@ -122,6 +162,7 @@ func (m *Model) SetValue(s string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
empty := len(m.value) == 0
|
||||||
m.Err = nil
|
m.Err = nil
|
||||||
|
|
||||||
runes := []rune(s)
|
runes := []rune(s)
|
||||||
@@ -130,7 +171,7 @@ func (m *Model) SetValue(s string) {
|
|||||||
} else {
|
} else {
|
||||||
m.value = runes
|
m.value = runes
|
||||||
}
|
}
|
||||||
if m.pos > len(m.value) {
|
if (m.pos == 0 && empty) || m.pos > len(m.value) {
|
||||||
m.SetCursor(len(m.value))
|
m.SetCursor(len(m.value))
|
||||||
}
|
}
|
||||||
m.handleOverflow()
|
m.handleOverflow()
|
||||||
@@ -169,7 +210,7 @@ func (m Model) Focused() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Focus sets the focus state on the model. When the model is in focus it can
|
// Focus sets the focus state on the model. When the model is in focus it can
|
||||||
// receive keyboard input and the cursor will be hidden.
|
// receive keyboard input and the cursor will be shown.
|
||||||
func (m *Model) Focus() tea.Cmd {
|
func (m *Model) Focus() tea.Cmd {
|
||||||
m.focus = true
|
m.focus = true
|
||||||
return m.Cursor.Focus()
|
return m.Cursor.Focus()
|
||||||
@@ -299,8 +340,8 @@ func (m *Model) deleteAfterCursor() {
|
|||||||
m.SetCursor(len(m.value))
|
m.SetCursor(len(m.value))
|
||||||
}
|
}
|
||||||
|
|
||||||
// deleteWordLeft deletes the word left to the cursor.
|
// deleteWordBackward deletes the word left to the cursor.
|
||||||
func (m *Model) deleteWordLeft() {
|
func (m *Model) deleteWordBackward() {
|
||||||
if m.pos == 0 || len(m.value) == 0 {
|
if m.pos == 0 || len(m.value) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -343,10 +384,10 @@ func (m *Model) deleteWordLeft() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// deleteWordRight deletes the word right to the cursor If input is masked
|
// deleteWordForward deletes the word right to the cursor If input is masked
|
||||||
// delete everything after the cursor so as not to reveal word breaks in the
|
// delete everything after the cursor so as not to reveal word breaks in the
|
||||||
// masked input.
|
// masked input.
|
||||||
func (m *Model) deleteWordRight() {
|
func (m *Model) deleteWordForward() {
|
||||||
if m.pos >= len(m.value) || len(m.value) == 0 {
|
if m.pos >= len(m.value) || len(m.value) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -384,9 +425,9 @@ func (m *Model) deleteWordRight() {
|
|||||||
m.SetCursor(oldPos)
|
m.SetCursor(oldPos)
|
||||||
}
|
}
|
||||||
|
|
||||||
// wordLeft moves the cursor one word to the left. If input is masked, move
|
// wordBackward moves the cursor one word to the left. If input is masked, move
|
||||||
// input to the start so as not to reveal word breaks in the masked input.
|
// input to the start so as not to reveal word breaks in the masked input.
|
||||||
func (m *Model) wordLeft() {
|
func (m *Model) wordBackward() {
|
||||||
if m.pos == 0 || len(m.value) == 0 {
|
if m.pos == 0 || len(m.value) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -416,9 +457,9 @@ func (m *Model) wordLeft() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// wordRight moves the cursor one word to the right. If the input is masked,
|
// wordForward moves the cursor one word to the right. If the input is masked,
|
||||||
// move input to the end so as not to reveal word breaks in the masked input.
|
// move input to the end so as not to reveal word breaks in the masked input.
|
||||||
func (m *Model) wordRight() {
|
func (m *Model) wordForward() {
|
||||||
if m.pos >= len(m.value) || len(m.value) == 0 {
|
if m.pos >= len(m.value) || len(m.value) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -472,68 +513,49 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
|||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
switch msg.Type {
|
switch {
|
||||||
case tea.KeyBackspace, tea.KeyCtrlH: // delete character before cursor
|
case key.Matches(msg, m.KeyMap.DeleteWordBackward):
|
||||||
m.Err = nil
|
m.Err = nil
|
||||||
|
m.deleteWordBackward()
|
||||||
if msg.Alt {
|
case key.Matches(msg, m.KeyMap.DeleteCharacterBackward):
|
||||||
m.deleteWordLeft()
|
m.Err = nil
|
||||||
} else {
|
if len(m.value) > 0 {
|
||||||
if len(m.value) > 0 {
|
m.value = append(m.value[:max(0, m.pos-1)], m.value[m.pos:]...)
|
||||||
m.value = append(m.value[:max(0, m.pos-1)], m.value[m.pos:]...)
|
if m.pos > 0 {
|
||||||
if m.pos > 0 {
|
m.SetCursor(m.pos - 1)
|
||||||
m.SetCursor(m.pos - 1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case tea.KeyLeft, tea.KeyCtrlB:
|
case key.Matches(msg, m.KeyMap.WordBackward):
|
||||||
if msg.Alt { // alt+left arrow, back one word
|
m.wordBackward()
|
||||||
m.wordLeft()
|
case key.Matches(msg, m.KeyMap.CharacterBackward):
|
||||||
break
|
if m.pos > 0 {
|
||||||
}
|
|
||||||
if m.pos > 0 { // left arrow, ^F, back one character
|
|
||||||
m.SetCursor(m.pos - 1)
|
m.SetCursor(m.pos - 1)
|
||||||
}
|
}
|
||||||
case tea.KeyRight, tea.KeyCtrlF:
|
case key.Matches(msg, m.KeyMap.WordForward):
|
||||||
if msg.Alt { // alt+right arrow, forward one word
|
m.wordForward()
|
||||||
m.wordRight()
|
case key.Matches(msg, m.KeyMap.CharacterForward):
|
||||||
break
|
if m.pos < len(m.value) {
|
||||||
}
|
|
||||||
if m.pos < len(m.value) { // right arrow, ^F, forward one character
|
|
||||||
m.SetCursor(m.pos + 1)
|
m.SetCursor(m.pos + 1)
|
||||||
}
|
}
|
||||||
case tea.KeyCtrlW: // ^W, delete word left of cursor
|
case key.Matches(msg, m.KeyMap.DeleteWordBackward):
|
||||||
m.deleteWordLeft()
|
m.deleteWordBackward()
|
||||||
case tea.KeyHome, tea.KeyCtrlA: // ^A, go to beginning
|
case key.Matches(msg, m.KeyMap.LineStart):
|
||||||
m.CursorStart()
|
m.CursorStart()
|
||||||
case tea.KeyDelete, tea.KeyCtrlD: // ^D, delete char under cursor
|
case key.Matches(msg, m.KeyMap.DeleteCharacterForward):
|
||||||
if len(m.value) > 0 && m.pos < len(m.value) {
|
if len(m.value) > 0 && m.pos < len(m.value) {
|
||||||
m.value = append(m.value[:m.pos], m.value[m.pos+1:]...)
|
m.value = append(m.value[:m.pos], m.value[m.pos+1:]...)
|
||||||
}
|
}
|
||||||
case tea.KeyCtrlE, tea.KeyEnd: // ^E, go to end
|
case key.Matches(msg, m.KeyMap.LineEnd):
|
||||||
m.CursorEnd()
|
m.CursorEnd()
|
||||||
case tea.KeyCtrlK: // ^K, kill text after cursor
|
case key.Matches(msg, m.KeyMap.DeleteAfterCursor):
|
||||||
m.deleteAfterCursor()
|
m.deleteAfterCursor()
|
||||||
case tea.KeyCtrlU: // ^U, kill text before cursor
|
case key.Matches(msg, m.KeyMap.DeleteBeforeCursor):
|
||||||
m.deleteBeforeCursor()
|
m.deleteBeforeCursor()
|
||||||
case tea.KeyCtrlV: // ^V paste
|
case key.Matches(msg, m.KeyMap.Paste):
|
||||||
return m, Paste
|
return m, Paste
|
||||||
case tea.KeyRunes, tea.KeySpace: // input regular characters
|
case key.Matches(msg, m.KeyMap.DeleteWordForward):
|
||||||
if msg.Alt && len(msg.Runes) == 1 {
|
m.deleteWordForward()
|
||||||
if msg.Runes[0] == 'd' { // alt+d, delete word right of cursor
|
default:
|
||||||
m.deleteWordRight()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if msg.Runes[0] == 'b' { // alt+b, back one word
|
|
||||||
m.wordLeft()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if msg.Runes[0] == 'f' { // alt+f, forward one word
|
|
||||||
m.wordRight()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Input a regular character
|
// Input a regular character
|
||||||
if m.CharLimit <= 0 || len(m.value) < m.CharLimit {
|
if m.CharLimit <= 0 || len(m.value) < m.CharLimit {
|
||||||
runes := msg.Runes
|
runes := msg.Runes
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
package viewport
|
package viewport
|
||||||
|
|
||||||
import "github.com/charmbracelet/bubbles/key"
|
import "github.com/Maks1mS/bubbles/key"
|
||||||
|
|
||||||
const spacebar = " "
|
const spacebar = " "
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/key"
|
"github.com/Maks1mS/bubbles/key"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
)
|
)
|
||||||
@@ -207,6 +207,16 @@ func (m *Model) LineUp(n int) (lines []string) {
|
|||||||
return m.visibleLines()
|
return m.visibleLines()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TotalLineCount returns the total number of lines (both hidden and visible) within the viewport.
|
||||||
|
func (m Model) TotalLineCount() int {
|
||||||
|
return len(m.lines)
|
||||||
|
}
|
||||||
|
|
||||||
|
// VisibleLineCount returns the number of the visible lines within the viewport.
|
||||||
|
func (m Model) VisibleLineCount() int {
|
||||||
|
return len(m.visibleLines())
|
||||||
|
}
|
||||||
|
|
||||||
// GotoTop sets the viewport to the top position.
|
// GotoTop sets the viewport to the top position.
|
||||||
func (m *Model) GotoTop() (lines []string) {
|
func (m *Model) GotoTop() (lines []string) {
|
||||||
if m.AtTop() {
|
if m.AtTop() {
|
||||||
@@ -240,9 +250,8 @@ func Sync(m Model) tea.Cmd {
|
|||||||
// number of lines. Use Model.ViewDown to get the lines that should be rendered.
|
// number of lines. Use Model.ViewDown to get the lines that should be rendered.
|
||||||
// For example:
|
// For example:
|
||||||
//
|
//
|
||||||
// lines := model.ViewDown(1)
|
// lines := model.ViewDown(1)
|
||||||
// cmd := ViewDown(m, lines)
|
// cmd := ViewDown(m, lines)
|
||||||
//
|
|
||||||
func ViewDown(m Model, lines []string) tea.Cmd {
|
func ViewDown(m Model, lines []string) tea.Cmd {
|
||||||
if len(lines) == 0 {
|
if len(lines) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user