Skip to content

Commit 3ea5fad

Browse files
committed
initial commit
0 parents  commit 3ea5fad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+9823
-0
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
5+
---
6+
7+
**Describe the bug**
8+
A clear and concise description of what the bug is.
9+
10+
**To Reproduce**
11+
Steps to reproduce the behavior. Code samples if possible.
12+
13+
**Expected behavior**
14+
A clear and concise description of what you expected to happen.
15+
16+
**Screenshots**
17+
If applicable, add screenshots to help explain your problem.
18+
19+
**Software (please complete the following information):**
20+
- OS: [e.g. OSX]
21+
- GoLang Version [e.g. 1.10]
22+
23+
**Additional context**
24+
Add any other context about the problem here.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
5+
---
6+
7+
**Is your feature request related to a problem? Please describe.**
8+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
9+
10+
**Describe the solution you'd like**
11+
A clear and concise description of what you want to happen.
12+
13+
**Describe alternatives you've considered**
14+
A clear and concise description of any alternative solutions or features you've considered.
15+
16+
**Additional context**
17+
Add any other context or screenshots about the feature request here.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Proposed Changes
2+
-
3+
-
4+
-
5+
6+
Fixes #<insert Issue # here if applicable>.

.github/workflows/ci.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: CI
2+
3+
on:
4+
# Pushes and pulls to all branches
5+
push:
6+
pull_request:
7+
8+
# Run on the first day of every month
9+
schedule:
10+
- cron: "0 0 1 * *"
11+
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
15+
jobs:
16+
# Build and test everything
17+
build:
18+
runs-on: ubuntu-latest
19+
steps:
20+
# Checkout the code
21+
- name: Checkout Code
22+
uses: actions/checkout@v3
23+
24+
# Set up the GoLang environment
25+
- name: Set up Go
26+
uses: actions/setup-go@v4
27+
with:
28+
go-version: '1.20'
29+
30+
# Download all the tools used in the steps that follow
31+
- name: Set up Tools
32+
run: |
33+
go install github.com/fzipp/gocyclo/cmd/gocyclo@v0.5.1
34+
go install github.com/mattn/goveralls@v0.0.12
35+
go install go.uber.org/mock/mockgen@latest
36+
37+
# Run all the unit-tests
38+
- name: Test
39+
run: |
40+
make test
41+
42+
# Run the benchmarks to ensure no performance degradation
43+
- name: Benchmark
44+
run: make bench
45+
46+
#
47+
# # Upload all the unit-test coverage reports to Coveralls
48+
# - name: Upload Coverage Report
49+
# env:
50+
# COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
# run: goveralls -service=github -coverprofile=.coverprofile
52+
#

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.idea/
2+
/demo*
3+
/profile/
4+
.coverprofile
5+
*.prof
6+
*.swp

CODE_OF_CONDUCT.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
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, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
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.
28+
29+
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.
30+
31+
## Scope
32+
33+
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.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at jedib0t@outlook.com. The project team will review and investigate all complaints, and will respond in a way that it deems 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.
38+
39+
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.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 jedib0t
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.PHONY: all test
2+
3+
default: test
4+
5+
all: test bench
6+
7+
bench:
8+
go test ./... -bench=. -benchmem
9+
10+
cyclo:
11+
gocyclo -over 13 ./*/*.go
12+
13+
fmt:
14+
go fmt $(shell go list ./...)
15+
16+
gen:
17+
mockgen -destination mocks/input/mock_reader.go github.com/jedib0t/go-prompter/input Reader
18+
mockgen -destination mocks/prompt/mock_prompter.go github.com/jedib0t/go-prompter/prompt Prompter
19+
20+
run:
21+
go run ./examples/prompt/sql
22+
23+
test: gen fmt vet cyclo
24+
go test -cover -coverprofile=.coverprofile -race $(shell go list ./...)
25+
26+
tools:
27+
go install github.com/fzipp/gocyclo/cmd/gocyclo@v0.5.1
28+
go install go.uber.org/mock/mockgen@latest
29+
30+
vet:
31+
go vet $(shell go list ./...)
32+

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# go-prompter
2+
3+
[![Go Reference](https://pkg.go.dev/badge/github.com/jedib0t/go-prompter.svg)](https://pkg.go.dev/github.com/jedib0t/go-prompter)
4+
![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)
5+
[![Build Status](https://github.com/jedib0t/go-prompter/workflows/CI/badge.svg?branch=main)](https://github.com/jedib0t/go-prompter/actions?query=workflow%3ACI+event%3Apush+branch%3Amain)
6+
[![Coverage Status](https://coveralls.io/repos/github/jedib0t/go-prompter/badge.svg?branch=main)](https://coveralls.io/github/jedib0t/go-prompter?branch=main)
7+
[![Go Report Card](https://goreportcard.com/badge/github.com/jedib0t/go-prompter)](https://goreportcard.com/report/github.com/jedib0t/go-prompter)
8+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=jedib0t_go-prompter&metric=alert_status)](https://sonarcloud.io/dashboard?id=jedib0t_go-prompter)
9+
10+
Build full-featured CLI prompts in GoLang.
11+
12+
A SQL prompt demo with most of the major features in play:
13+
14+
<img src="prompt/demo.gif" alt="Demo"/>
15+
16+
## Features
17+
18+
* Single-line and Multi-line prompt with line numbers
19+
* [Syntax-Highlighting](prompt/syntax_highlighter.go) - use [Chroma](https://github.com/alecthomas/chroma) or roll-your-own
20+
* Flexible [Auto-Complete](prompt/auto_completer.go) drop-downs
21+
* Start with built-in `AutoCompleter` for simple Keywords `Prompter.SetAutoCompleter(...)`
22+
* Expand to context based additional Keywords using `Prompter.SetAutoCompleterContextual(...)`
23+
* Generate prompts with or without a "prefix"
24+
* Header and Footer generator functions for dynamic content
25+
* History integration with built-in go-back/go-forward/list/rerun
26+
* Completely customizable [KeyMap](prompt/key_map.go)
27+
* Control what Actions can be triggered by what (special) Key-combinations
28+
* Custom command-shortcuts if the KeyMap is not flexible enough
29+
* Extremely flexible [Styling/Customization](prompt/style.go)
30+
* Auto-Complete look and feel
31+
* Cursor look and feel
32+
* Dimensions (height/width)
33+
* Line-Numbers look and feel
34+
* Scrollbar look and feel
35+
36+
## Bonus
37+
38+
* [Input](input) package that wraps around [bubbletea](https://github.com/charmbracelet/bubbletea)
39+
and provides a basic interface to capture input events
40+
* Key-presses
41+
* Mouse-clicks and motion
42+
* Window/terminal resizes
43+
* [Powerline](powerline) package to generate Powerline-like lines
44+
* Supports "segments" on both left and right sides
45+
* Can auto-adjust and auto-remove segments to meet terminal width limitations
46+
* Usable as header and/or prefix for the Prompt

SECURITY.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
| Version | Supported |
6+
| ------- | ------------------ |
7+
| 0.x.x | :white_check_mark: |
8+
9+
## Reporting a Vulnerability
10+
11+
Please create a new issue on this repo describing the vulnerability,
12+
and (if known) how to resolve it.

examples/color/main.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"strings"
7+
8+
"github.com/jedib0t/go-pretty/v6/text"
9+
"github.com/jedib0t/go-prompter/prompt"
10+
"github.com/muesli/termenv"
11+
"golang.org/x/term"
12+
)
13+
14+
var (
15+
colorsTitle = prompt.Color{
16+
Foreground: termenv.BackgroundColor(),
17+
Background: termenv.ForegroundColor(),
18+
}
19+
)
20+
21+
func main() {
22+
termWidth, _, _ := term.GetSize(int(os.Stdout.Fd()))
23+
24+
out := strings.Builder{}
25+
out.WriteString("\n")
26+
out.WriteString(colorsTitle.Sprint(" 256-color Mode "))
27+
out.WriteString("\n")
28+
for bg := 0; bg < 256; bg++ {
29+
if bg == 0 {
30+
out.WriteString("\n  Standard Colors High-Intensity Colors\n")
31+
} else if bg == 8 {
32+
out.WriteString(" ")
33+
} else if bg == 16 {
34+
out.WriteString("\n\n216 Colors\n")
35+
} else if bg > 16 && bg < 232 && (bg-16)%18 == 0 { // 216-colors
36+
if termWidth < 180 {
37+
out.WriteString("\n") // 18 colors in one line
38+
} else if (bg-16)%36 == 0 {
39+
out.WriteString("\n") // 36 colors in one line
40+
}
41+
} else if bg == 232 {
42+
out.WriteString("\n\nGrayscale Colors\n")
43+
} else if bg == 244 {
44+
if termWidth < 120 { // 12 grayscale colors in one line
45+
out.WriteString("\n")
46+
}
47+
}
48+
49+
// determine foreground color based on how bright the background is
50+
fg := 16 // black by default
51+
if bg >= 16 && (bg-16)%36 < 18 && bg < 244 {
52+
fg = 15 // white for darker background
53+
}
54+
c := prompt.Color{
55+
Foreground: termenv.ANSI256Color(fg),
56+
Background: termenv.ANSI256Color(bg),
57+
}
58+
out.WriteString(c.Sprintf(" %03d ", bg))
59+
}
60+
out.WriteString("\n")
61+
62+
for _, line := range strings.Split(out.String(), "\n") {
63+
fmt.Println(text.AlignCenter.Apply(line, termWidth))
64+
}
65+
}

0 commit comments

Comments
 (0)