Skip to content

Commit

Permalink
Merge pull request #26 from alphatroya/go-install
Browse files Browse the repository at this point in the history
Rename package to github.com/mathaou/termdbms
  • Loading branch information
mathaou authored Apr 15, 2022
2 parents f21f804 + c82e908 commit fb71ac6
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 54 deletions.
4 changes: 2 additions & 2 deletions database/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Database interface {
}

type Update struct {
v map[string]interface{} // these are anchors to ensure the right row/col gets updated
v map[string]interface{} // these are anchors to ensure the right row/col gets updated
Column string // this is the header
Update interface{} // this is the new cell value
TableName string
Expand Down Expand Up @@ -73,4 +73,4 @@ func ProcessSqlQueryForDatabaseType(q Query, rowData map[string]interface{}, sch
(*db).Update(conv)
break
}
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module termdbms
module github.com/mathaou/termdbms

go 1.16

Expand Down
2 changes: 1 addition & 1 deletion list/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package list

import (
"github.com/charmbracelet/lipgloss"
"termdbms/tuiutil"
"github.com/mathaou/termdbms/tuiutil"
)

const (
Expand Down
18 changes: 10 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import (
"database/sql"
"flag"
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/termenv"
"io/fs"
"io/ioutil"
_ "modernc.org/sqlite"
"os"
"path/filepath"
"strings"
"termdbms/database"
. "termdbms/tuiutil"
. "termdbms/viewer"

. "github.com/mathaou/termdbms/tuiutil"
. "github.com/mathaou/termdbms/viewer"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/mathaou/termdbms/database"
"github.com/muesli/termenv"
_ "modernc.org/sqlite"
)

type DatabaseType string
Expand Down Expand Up @@ -102,7 +104,7 @@ func main() {
return nil
})
} else {
os.Mkdir(HiddenTmpDirectoryName, 0777)
os.Mkdir(HiddenTmpDirectoryName, 0o777)
}

database.IsCSV = strings.HasSuffix(path, ".csv")
Expand Down
1 change: 0 additions & 1 deletion tuiutil/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const (
TextColorKey = "TextColor"
)


// styling functions
var (
Highlight = func() string {
Expand Down
6 changes: 3 additions & 3 deletions viewer/defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"termdbms/database"
"termdbms/list"
"github.com/mathaou/termdbms/database"
"github.com/mathaou/termdbms/list"
)

type SQLSnippet struct {
Query string `json:"Query"`
Name string `json:"Name"`
Name string `json:"Name"`
}

type ScrollData struct {
Expand Down
9 changes: 5 additions & 4 deletions viewer/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package viewer
import (
"encoding/json"
"fmt"
"os"
"time"

"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"os"
"termdbms/list"
"termdbms/tuiutil"
"time"
"github.com/mathaou/termdbms/list"
"github.com/mathaou/termdbms/tuiutil"
)

// HandleMouseEvents does that
Expand Down
7 changes: 4 additions & 3 deletions viewer/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package viewer

import (
"fmt"
"strings"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"strings"
"termdbms/database"
"termdbms/tuiutil"
"github.com/mathaou/termdbms/database"
"github.com/mathaou/termdbms/tuiutil"
)

type Command func(m *TuiModel) tea.Cmd
Expand Down
11 changes: 6 additions & 5 deletions viewer/lineedit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"math/rand"
"os"
"strings"
"termdbms/database"
"termdbms/tuiutil"
"time"

"github.com/mathaou/termdbms/database"
"github.com/mathaou/termdbms/tuiutil"
)

const (
Expand Down Expand Up @@ -128,7 +129,7 @@ func EditEnter(m *TuiModel) {
return
} else if input == ":clip" {
ExitToDefaultView(m)
if len( m.ClipboardList.Items()) == 0 {
if len(m.ClipboardList.Items()) == 0 {
return
}
m.UI.ShowClipboard = true
Expand Down Expand Up @@ -186,14 +187,14 @@ func EditEnter(m *TuiModel) {
}
m.Clipboard = append(m.Clipboard, SQLSnippet{
Query: input,
Name: title,
Name: title,
})
b, _ := json.Marshal(m.Clipboard)
snippetsFile := fmt.Sprintf("%s/%s", HiddenTmpDirectoryName, SQLSnippetsFile)
f, _ := os.OpenFile(snippetsFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0775)
f.Write(b)
f.Close()
m.WriteMessage(fmt.Sprintf("Wrote SQL snippet %s to %s. Total count is %d", title, snippetsFile, len(m.ClipboardList.Items()) + 1))
m.WriteMessage(fmt.Sprintf("Wrote SQL snippet %s to %s. Total count is %d", title, snippetsFile, len(m.ClipboardList.Items())+1))
}
m.TextInput.Model.SetValue("")
}
Expand Down
3 changes: 2 additions & 1 deletion viewer/mode.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package viewer

import (
tea "github.com/charmbracelet/bubbletea"
"strings"

tea "github.com/charmbracelet/bubbletea"
)

var (
Expand Down
9 changes: 5 additions & 4 deletions viewer/modelutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"database/sql"
"encoding/json"
"fmt"
tea "github.com/charmbracelet/bubbletea"
"os"
"strings"
"termdbms/database"
"termdbms/list"
"termdbms/tuiutil"

tea "github.com/charmbracelet/bubbletea"
"github.com/mathaou/termdbms/database"
"github.com/mathaou/termdbms/list"
"github.com/mathaou/termdbms/tuiutil"
)

func (m *TuiModel) WriteMessage(s string) {
Expand Down
3 changes: 2 additions & 1 deletion viewer/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"os"
"path"
"strings"
"termdbms/database"

"github.com/mathaou/termdbms/database"
)

var (
Expand Down
13 changes: 7 additions & 6 deletions viewer/snippets.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package viewer

import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"io"
"strings"
"termdbms/list"
"termdbms/tuiutil"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/mathaou/termdbms/list"
"github.com/mathaou/termdbms/tuiutil"
)

var (
Expand Down Expand Up @@ -50,7 +51,7 @@ func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list

str := fmt.Sprintf("%d) %s%s | ", index+1, strings.Repeat(" ", digits-incomingDigits),
i.Title())
query := localStyle.Render(i.Query[0:Min(TUIWidth - 10, Max(len(i.Query) - 1, len(i.Query) - 1 - len(str)))]) // padding + tab + padding
query := localStyle.Render(i.Query[0:Min(TUIWidth-10, Max(len(i.Query)-1, len(i.Query)-1-len(str)))]) // padding + tab + padding
str += strings.ReplaceAll(query, "\n", "")

localStyle = style.Copy().PaddingLeft(4)
Expand All @@ -67,7 +68,7 @@ func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list

return lipgloss.JoinHorizontal(lipgloss.Left,
localStyle.
Render("> "),
Render("> "),
style.Render(s))
}
}
Expand Down
9 changes: 5 additions & 4 deletions viewer/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package viewer

import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"strings"
"termdbms/database"
"termdbms/tuiutil"
"time"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/mathaou/termdbms/database"
"github.com/mathaou/termdbms/tuiutil"
)

type TableAssembly func(m *TuiModel, s *string, c *chan bool)
Expand Down
3 changes: 2 additions & 1 deletion viewer/tableutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package viewer

import (
"errors"

"github.com/charmbracelet/lipgloss"
"termdbms/tuiutil"
"github.com/mathaou/termdbms/tuiutil"
)

var maxHeaders int
Expand Down
9 changes: 5 additions & 4 deletions viewer/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package viewer

import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/reflow/wordwrap"
"strconv"
"strings"
"termdbms/tuiutil"
"time"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/mathaou/termdbms/tuiutil"
"github.com/muesli/reflow/wordwrap"
)

var (
Expand Down
5 changes: 3 additions & 2 deletions viewer/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/charmbracelet/lipgloss"
"hash/fnv"
"io"
"math/rand"
Expand All @@ -15,11 +14,13 @@ import (
"strconv"
"strings"
"time"

"github.com/charmbracelet/lipgloss"
)

const (
HiddenTmpDirectoryName = ".termdbms"
SQLSnippetsFile = "snippets.termdbms"
SQLSnippetsFile = "snippets.termdbms"
)

func TruncateIfApplicable(m *TuiModel, conv string) (s string) {
Expand Down
7 changes: 4 additions & 3 deletions viewer/viewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package viewer

import (
"fmt"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"termdbms/list"
"termdbms/tuiutil"
"github.com/mathaou/termdbms/list"
"github.com/mathaou/termdbms/tuiutil"
)

var (
Expand Down Expand Up @@ -153,7 +154,7 @@ func (m TuiModel) View() string {
}(&content)

if m.UI.ShowClipboard {
<- done
<-done
return content
}

Expand Down

0 comments on commit fb71ac6

Please sign in to comment.