Skip to content

Commit

Permalink
Merge branch 'main' into fix-colors
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgerojas26 committed Jul 20, 2024
2 parents 702f080 + fa2c6be commit db6461f
Show file tree
Hide file tree
Showing 21 changed files with 656 additions and 390 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ jobs:
-
name: Set up Go
uses: actions/setup-go@v5

-
name: Golangci-lint
uses: golangci/[email protected]

-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
Expand Down
156 changes: 156 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
# golangci-lint configuration file made by @ccoVeille
# Source: https://github.com/ccoVeille/golangci-lint-config-examples/
# Author: @ccoVeille
# License: MIT
# Variant: 03-safe
# Version: v1.0.0
#
linters:
# some linters are enabled by default
# https://golangci-lint.run/usage/linters/
#
# enable some extra linters
enable:
# Errcheck is a program for checking for unchecked errors in Go code.
- errcheck

# Linter for Go source code that specializes in simplifying code.
- gosimple

# Vet examines Go source code and reports suspicious constructs.
- govet

# Detects when assignments to existing variables are not used.
- ineffassign

# It's a set of rules from staticcheck. See https://staticcheck.io/
- staticcheck

# Fast, configurable, extensible, flexible, and beautiful linter for Go.
# Drop-in replacement of golint.
- revive

# check imports order and makes it always deterministic.
- gci

# make sure to use t.Helper() when needed
- thelper

# mirror suggests rewrites to avoid unnecessary []byte/string conversion
- mirror

# detect the possibility to use variables/constants from the Go standard library.
- usestdlibvars

# Finds commonly misspelled English words.
- misspell

# Checks for duplicate words in the source code.
- dupword

linters-settings:
gci: # define the section orders for imports
sections:
# Standard section: captures all standard packages.
- standard
# Default section: catchall that is not standard or custom
- default
# linters that related to local tool, so they should be separated
- localmodule

revive:
rules:
# these are the default revive rules
# you can remove the whole "rules" node if you want
# BUT
# ! /!\ they all need to be present when you want to add more rules than the default ones
# otherwise, you won't have the default rules, but only the ones you define in the "rules" node

# Blank import should be only in a main or test package, or have a comment justifying it.
- name: blank-imports

# context.Context() should be the first parameter of a function when provided as argument.
- name: context-as-argument
arguments:
- allowTypesBefore: "*testing.T"

# Basic types should not be used as a key in `context.WithValue`
- name: context-keys-type

# Importing with `.` makes the programs much harder to understand
- name: dot-imports

# Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring.
- name: empty-block

# for better readability, variables of type `error` must be named with the prefix `err`.
- name: error-naming

# for better readability, the errors should be last in the list of returned values by a function.
- name: error-return

# for better readability, error messages should not be capitalized or end with punctuation or a newline.
- name: error-strings

# report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible
- name: errorf

# incrementing an integer variable by 1 is recommended to be done using the `++` operator
- name: increment-decrement

# highlights redundant else-blocks that can be eliminated from the code
- name: indent-error-flow

# This rule suggests a shorter way of writing ranges that do not use the second value.
- name: range

# receiver names in a method should reflect the struct name (p for Person, for example)
- name: receiver-naming

# redefining built in names (true, false, append, make) can lead to bugs very difficult to detect.
- name: redefines-builtin-id

# redundant else-blocks that can be eliminated from the code.
- name: superfluous-else

# prevent confusing name for variables when using `time` package
- name: time-naming

# warns when an exported function or method returns a value of an un-exported type.
- name: unexported-return

# spots and proposes to remove unreachable code. also helps to spot errors
- name: unreachable-code

# Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug.
- name: unused-parameter

# report when a variable declaration can be simplified
- name: var-declaration

# warns when initialism, variable or package naming conventions are not followed.
- name: var-naming

dupword:
# Keywords used to ignore detection.
# Default: []
ignore:
# - "blah" # this will accept "blah blah …" as a valid duplicate word

misspell:
# Correct spellings using locale preferences for US or UK.
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
# Default ("") is to use a neutral variety of English.
locale: US

# List of words to ignore
# among the one defined in https://github.com/golangci/misspell/blob/master/words.go
ignore-words:
# - valor
# - and

# Extra word corrections.
extra-words:
# - typo: "whattever"
# correction: "whatever"
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@
![Product Name Screen Shot][product-screenshot1]
![Product Name Screen Shot][product-screenshot2]

This project is heavily inspired by [Lazygit](https://github.com/jesseduffield/lazygit), which i think is the best TUI client for Git.
This project is heavily inspired by [Lazygit](https://github.com/jesseduffield/lazygit), which I think is the best TUI client for Git.

I wanted to have a tool like that, but for SQL. I didn't find one that fits my needs so i created one myself.
I wanted to have a tool like that, but for SQL. I didn't find one that fits my needs, so I created one myself.

I live in the terminal, so if you are like me, this tool can become handy for you too.

This is my first Open Source project, also, this is my first Golang project. I am not a brilliant programmer. I am just a typical Javascript developer that wanted to learn a new language, i also wanted a TUI SQL Client, so, white and bottled.
This is my first Open Source project, also, this is my first Go project. I am not a brilliant programmer. I am just a typical JavaScript developer that wanted to learn a new language, I also wanted a TUI SQL Client, so white and bottled.

This project is in ALPHA stage, please feel free to critize my spaghetti code.
This project is in ALPHA stage, please feel free to complain about my spaghetti code.

I use Lazysql daily in my ful time job as a fullstack javascript developer in it's current (buggy xD) state. So, the plan is to improve and fix my little boy as a side project in my free time.
I use Lazysql daily in my full-time job as a full-stack javascript developer in its current (buggy xD) state. So, the plan is to improve and fix my little boy as a side-project in my free time.

### Built With

Expand All @@ -74,7 +74,7 @@ I use Lazysql daily in my ful time job as a fullstack javascript developer in it
## Features

- [x] Cross-platform (macOS, Windows, Linux)
- [x] VIM Keybindings
- [x] Vim Keybindings
- [x] Can manage multiple connections (Backspace)
- [x] Tabs
- [x] SQL Editor (CTRL + e)
Expand All @@ -100,11 +100,11 @@ go install github.com/jorgerojas26/lazysql@latest

#### Binary Releases

For Windows, Mac OS or Linux, you can download a binary release [here](https://github.com/jorgerojas26/lazysql/releases)
For Windows, macOS or Linux, you can download a binary release [here](https://github.com/jorgerojas26/lazysql/releases)

#### Third party (maintained by the community)

Archlinux users can install it from the AUR with:
Arch Linux users can install it from the AUR with:

```bash
paru -S lazysql
Expand Down Expand Up @@ -141,7 +141,7 @@ $ lazysql
## Support

- [x] MySQL
- [x] Postgres
- [x] PostgreSQL
- [x] SQLite
- [ ] MSSQL
- [ ] MongoDB
Expand Down Expand Up @@ -216,7 +216,7 @@ odbc+postgres://user:pass@localhost:port/dbname?option1=

## Roadmap

- [ ] Support for NOSQL databases
- [ ] Support for NoSQL databases
- [ ] Columns and indexes creation through TUI
- [ ] Table tree input filter
- [ ] Custom keybindings
Expand All @@ -231,7 +231,7 @@ See the [open issues](https://github.com/jorgerojas26/lazysql/issues) for a full

## Contributing

Contributions, issues and pull requests are welcome!
Contributions, issues, and pull requests are welcome!

<p align="right">(<a href="#readme-top">back to top</a>)</p>

Expand All @@ -247,7 +247,7 @@ Distributed under the MIT License. See `LICENSE.txt` for more information.

## Contact

Jorge Rojas - [Linkedin](https://www.linkedin.com/in/jorgerojas26/) - [email protected]
Jorge Rojas - [LinkedIn](https://www.linkedin.com/in/jorgerojas26/) - [email protected]

<p align="right">(<a href="#readme-top">back to top</a>)</p>

Expand Down
80 changes: 44 additions & 36 deletions app/Keymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ package app

import (
"github.com/gdamore/tcell/v2"
. "github.com/jorgerojas26/lazysql/commands"
. "github.com/jorgerojas26/lazysql/keymap"

cmd "github.com/jorgerojas26/lazysql/commands"
"github.com/jorgerojas26/lazysql/keymap"
)

// local alias added for clarity purpose
type (
Bind = keymap.Bind
Key = keymap.Key
Map = keymap.Map
)

// KeymapSystem is the actual key mapping system.
Expand Down Expand Up @@ -31,54 +39,54 @@ func (c KeymapSystem) Group(name string) Map {

// Resolve translates a tcell.EventKey into a command based on the mappings in
// the global group
func (c KeymapSystem) Resolve(event *tcell.EventKey) Command {
func (c KeymapSystem) Resolve(event *tcell.EventKey) cmd.Command {
return c.Global.Resolve(event)
}

// Define a global KeymapSystem object with default keybinds
var Keymaps KeymapSystem = KeymapSystem{
var Keymaps = KeymapSystem{
Global: Map{
Bind{Key: Key{Char: 'L'}, Cmd: MoveRight},
Bind{Key: Key{Char: 'H'}, Cmd: MoveLeft},
Bind{Key: Key{Code: tcell.KeyCtrlE}, Cmd: SwitchToEditorView},
Bind{Key: Key{Code: tcell.KeyCtrlS}, Cmd: Save},
Bind{Key: Key{Char: 'q'}, Cmd: Quit},
Bind{Key: Key{Code: tcell.KeyBackspace2}, Cmd: SwitchToConnectionsView},
Bind{Key: Key{Char: 'L'}, Cmd: cmd.MoveRight},
Bind{Key: Key{Char: 'H'}, Cmd: cmd.MoveLeft},
Bind{Key: Key{Code: tcell.KeyCtrlE}, Cmd: cmd.SwitchToEditorView},
Bind{Key: Key{Code: tcell.KeyCtrlS}, Cmd: cmd.Save},
Bind{Key: Key{Char: 'q'}, Cmd: cmd.Quit},
Bind{Key: Key{Code: tcell.KeyBackspace2}, Cmd: cmd.SwitchToConnectionsView},
},
Groups: map[string]Map{
"tree": {
Bind{Key: Key{Char: 'g'}, Cmd: GotoTop},
Bind{Key: Key{Char: 'G'}, Cmd: GotoBottom},
Bind{Key: Key{Code: tcell.KeyEnter}, Cmd: Execute},
Bind{Key: Key{Char: 'j'}, Cmd: MoveDown},
Bind{Key: Key{Code: tcell.KeyDown}, Cmd: MoveDown},
Bind{Key: Key{Char: 'k'}, Cmd: MoveUp},
Bind{Key: Key{Code: tcell.KeyUp}, Cmd: MoveUp},
Bind{Key: Key{Char: 'g'}, Cmd: cmd.GotoTop},
Bind{Key: Key{Char: 'G'}, Cmd: cmd.GotoBottom},
Bind{Key: Key{Code: tcell.KeyEnter}, Cmd: cmd.Execute},
Bind{Key: Key{Char: 'j'}, Cmd: cmd.MoveDown},
Bind{Key: Key{Code: tcell.KeyDown}, Cmd: cmd.MoveDown},
Bind{Key: Key{Char: 'k'}, Cmd: cmd.MoveUp},
Bind{Key: Key{Code: tcell.KeyUp}, Cmd: cmd.MoveUp},
},
"table": {
Bind{Key: Key{Char: '/'}, Cmd: Search},
Bind{Key: Key{Char: 'c'}, Cmd: Edit},
Bind{Key: Key{Char: 'd'}, Cmd: Delete},
Bind{Key: Key{Char: 'w'}, Cmd: GotoNext},
Bind{Key: Key{Char: 'b'}, Cmd: GotoPrev},
Bind{Key: Key{Char: '$'}, Cmd: GotoEnd},
Bind{Key: Key{Char: '0'}, Cmd: GotoStart},
Bind{Key: Key{Char: 'y'}, Cmd: Copy},
Bind{Key: Key{Char: 'o'}, Cmd: AppendNewRow},
Bind{Key: Key{Char: '/'}, Cmd: cmd.Search},
Bind{Key: Key{Char: 'c'}, Cmd: cmd.Edit},
Bind{Key: Key{Char: 'd'}, Cmd: cmd.Delete},
Bind{Key: Key{Char: 'w'}, Cmd: cmd.GotoNext},
Bind{Key: Key{Char: 'b'}, Cmd: cmd.GotoPrev},
Bind{Key: Key{Char: '$'}, Cmd: cmd.GotoEnd},
Bind{Key: Key{Char: '0'}, Cmd: cmd.GotoStart},
Bind{Key: Key{Char: 'y'}, Cmd: cmd.Copy},
Bind{Key: Key{Char: 'o'}, Cmd: cmd.AppendNewRow},
// Tabs
Bind{Key: Key{Char: '['}, Cmd: TabPrev},
Bind{Key: Key{Char: ']'}, Cmd: TabNext},
Bind{Key: Key{Char: '{'}, Cmd: TabFirst},
Bind{Key: Key{Char: '}'}, Cmd: TabLast},
Bind{Key: Key{Char: 'X'}, Cmd: TabClose},
Bind{Key: Key{Char: '['}, Cmd: cmd.TabPrev},
Bind{Key: Key{Char: ']'}, Cmd: cmd.TabNext},
Bind{Key: Key{Char: '{'}, Cmd: cmd.TabFirst},
Bind{Key: Key{Char: '}'}, Cmd: cmd.TabLast},
Bind{Key: Key{Char: 'X'}, Cmd: cmd.TabClose},
// Pages
Bind{Key: Key{Char: '>'}, Cmd: PageNext},
Bind{Key: Key{Char: '<'}, Cmd: PagePrev},
Bind{Key: Key{Char: '>'}, Cmd: cmd.PageNext},
Bind{Key: Key{Char: '<'}, Cmd: cmd.PagePrev},
},
"editor": {
Bind{Key: Key{Code: tcell.KeyCtrlR}, Cmd: Execute},
Bind{Key: Key{Code: tcell.KeyEscape}, Cmd: Quit},
Bind{Key: Key{Code: tcell.KeyCtrlSpace}, Cmd: OpenInExternalEditor},
Bind{Key: Key{Code: tcell.KeyCtrlR}, Cmd: cmd.Execute},
Bind{Key: Key{Code: tcell.KeyEscape}, Cmd: cmd.Quit},
Bind{Key: Key{Code: tcell.KeyCtrlSpace}, Cmd: cmd.OpenInExternalEditor},
},
},
}
Loading

0 comments on commit db6461f

Please sign in to comment.