-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af4da50
commit e9366ae
Showing
5 changed files
with
264 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,55 @@ | ||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= | ||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= | ||
github.com/charmbracelet/bubbletea v0.26.6 h1:zTCWSuST+3yZYZnVSvbXwKOPRSNZceVeqpzOLN2zq1s= | ||
github.com/charmbracelet/bubbletea v0.26.6/go.mod h1:dz8CWPlfCCGLFbBlTY4N7bjLiyOGDJEnd2Muu7pOWhk= | ||
github.com/charmbracelet/lipgloss v0.11.0 h1:UoAcbQ6Qml8hDwSWs0Y1cB5TEQuZkDPH/ZqwWWYTG4g= | ||
github.com/charmbracelet/lipgloss v0.11.0/go.mod h1:1UdRTH9gYgpcdNN5oBtjbu/IzNKtzVtb7sqN1t9LNn8= | ||
github.com/charmbracelet/x/ansi v0.1.2 h1:6+LR39uG8DE6zAmbu023YlqjJHkYXDF1z36ZwzO4xZY= | ||
github.com/charmbracelet/x/ansi v0.1.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= | ||
github.com/charmbracelet/x/input v0.1.0 h1:TEsGSfZYQyOtp+STIjyBq6tpRaorH0qpwZUj8DavAhQ= | ||
github.com/charmbracelet/x/input v0.1.0/go.mod h1:ZZwaBxPF7IG8gWWzPUVqHEtWhc1+HXJPNuerJGRGZ28= | ||
github.com/charmbracelet/x/term v0.1.1 h1:3cosVAiPOig+EV4X9U+3LDgtwwAoEzJjNdwbXDjF6yI= | ||
github.com/charmbracelet/x/term v0.1.1/go.mod h1:wB1fHt5ECsu3mXYusyzcngVWWlu1KKUmmLhfgr/Flxw= | ||
github.com/charmbracelet/x/windows v0.1.0 h1:gTaxdvzDM5oMa/I2ZNF7wN78X/atWemG9Wph7Ika2k4= | ||
github.com/charmbracelet/x/windows v0.1.0/go.mod h1:GLEO/l+lizvFDBPLIOk+49gdX49L9YWMB5t+DZd0jkQ= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= | ||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= | ||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= | ||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
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/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= | ||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= | ||
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.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= | ||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= | ||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= | ||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= | ||
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= | ||
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= | ||
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= | ||
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= | ||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= | ||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= | ||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= | ||
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= | ||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= | ||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= | ||
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E= | ||
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= | ||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= | ||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= | ||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= | ||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= | ||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,199 @@ | ||
package main | ||
|
||
import "github.com/dyne/tgcom/cmd" | ||
import ( | ||
"github.com/dyne/tgcom/cmd" | ||
"os/exec" | ||
"os" | ||
"runtime" | ||
"fmt" | ||
"path/filepath" | ||
"github.com/charmbracelet/bubbletea" | ||
"github.com/dyne/tgcom/tui-tgcom/options_selector" | ||
"github.com/dyne/tgcom/tui-tgcom/files_selector" | ||
"github.com/dyne/tgcom/tui-tgcom/texts_selector" | ||
"github.com/dyne/tgcom/utils/modfile" // o solo modfile | ||
) | ||
|
||
func main() { | ||
cmd.Execute() | ||
//function main must be modified, but it shows that it works both with | ||
//flags and as a tui | ||
var mod int = 0 | ||
var num int | ||
if mod == 0 { | ||
cmd.Execute() | ||
_, err := fmt.Scanf("%d", &num) | ||
if err != nil { | ||
fmt.Println("Errore:", err) | ||
} | ||
} | ||
|
||
clearScreen() // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||
|
||
// initialize model for file selection | ||
model1 := file_selector.InitialModel() | ||
|
||
// select files | ||
p1, _ := tea.NewProgram(model1).Run() | ||
model1 = p1.(file_selector.Model) | ||
|
||
// Files []string contain the path for all the files user selects | ||
Files := model1.Files_Path // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||
|
||
// Ask if user wants fast or slow mode | ||
clearScreen() // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||
|
||
optionsz := []string{"Fast mode", "Slow mode"} | ||
|
||
model2 := option_selector.Model{ | ||
Options: optionsz, | ||
} | ||
|
||
// Esegui Init | ||
/* | ||
cmd2 := model2.Init() | ||
if cmd2 == nil { | ||
fmt.Println("Init command not executed") | ||
} | ||
*/ | ||
|
||
p2, _ := tea.NewProgram(model2).Run() | ||
model2 = p2.(option_selector.Model) | ||
|
||
// Speed is the string "Fast mode o Slow mode" | ||
speed := model2.Selected | ||
|
||
// Array that contains informations about how the user wants to modify each file | ||
var Actions []string | ||
var Labels []string | ||
|
||
switch speed { | ||
case "Fast mode": | ||
// Ask the user for the labels he wants to assign | ||
clearScreen() // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||
model3 := text_selector.Model{} | ||
|
||
// Esegui Init | ||
cmd3 := model3.Init() | ||
if cmd3 == nil { | ||
fmt.Println("Init command not executed") | ||
} | ||
|
||
p3, _ := tea.NewProgram(model3).Run() | ||
|
||
model3 = p3.(text_selector.Model) | ||
|
||
// update of Actions and Label | ||
for i := 0; i < len(Files); i++{ | ||
Actions = append(Actions, "toggle") | ||
Labels = append(Labels, model3.Input) | ||
} | ||
|
||
/* | ||
fmt.Println("Files:") | ||
fmt.Println(Files) | ||
fmt.Println("Azioni:") | ||
fmt.Println(Actions) | ||
fmt.Println("Labels:") | ||
fmt.Println(Labels) | ||
*/ | ||
|
||
case "Slow mode": | ||
var p4 tea.Model | ||
for i := 0; i < len(Files); i++ { | ||
// Ask the user the action to perform | ||
clearScreen() // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||
|
||
optionsz = []string{"toggle", "comment", "uncomment"} | ||
|
||
model4 := option_selector.Model{ | ||
Options: optionsz, | ||
} | ||
|
||
// Esegui Init | ||
/* | ||
cmd4 := model4.Init() | ||
if cmd4 == nil { | ||
fmt.Println("Init command not executed") | ||
} | ||
*/ | ||
|
||
p4, _ = tea.NewProgram(model4).Run() | ||
model4 = p4.(option_selector.Model) | ||
|
||
// Speed is the string "Fast mode o Slow mode" | ||
Actions = append(Actions, model4.Selected) // <<<<<<<<<<<<<<<<<<<<< | ||
|
||
// Ask the user for the lines/labels | ||
clearScreen() // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||
model5 := text_selector.Model{} | ||
|
||
// Esegui Init | ||
cmd5 := model5.Init() | ||
if cmd5 == nil { | ||
fmt.Println("Init command not executed") | ||
} | ||
|
||
p5, _ := tea.NewProgram(model5).Run() | ||
|
||
model5 = p5.(text_selector.Model) | ||
// Label contiene le stringhe di start e end | ||
Labels = append(Labels, model5.Input) // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< | ||
|
||
/* | ||
fmt.Println("Files:") | ||
fmt.Println(Files) | ||
fmt.Println("Azioni:") | ||
fmt.Println(Actions) | ||
fmt.Println("Labels:") | ||
fmt.Println(Labels) | ||
*/ | ||
} | ||
|
||
} | ||
|
||
// ora modifica i files | ||
var conf modfile.Config | ||
for i := 0; i < len(Files); i++ { | ||
currentFilePath, err := AbsToRel(Files[i]) | ||
if err != nil{ | ||
os.Exit(1) | ||
} | ||
conf = modfile.Config{Filename: currentFilePath, LineNum: Labels[i], Action: Actions[i]} | ||
fmt.Println(conf) | ||
|
||
err = modfile.ChangeFile(conf) | ||
if err != nil { | ||
os.Exit(0) | ||
} | ||
} | ||
} | ||
|
||
// clean the screen | ||
func clearScreen() { | ||
var cmd *exec.Cmd | ||
switch runtime.GOOS { | ||
case "windows": | ||
cmd = exec.Command("cmd", "/c", "cls") | ||
default: | ||
cmd = exec.Command("clear") | ||
} | ||
cmd.Stdout = os.Stdout | ||
cmd.Run() | ||
} | ||
|
||
// extract relative path from absolute path | ||
func AbsToRel(absPath string) (string, error) { | ||
// Get the current working directory | ||
currentDir, err := filepath.Abs(".") | ||
if err != nil { | ||
return "", fmt.Errorf("failed to get the current directory: %w", err) | ||
} | ||
|
||
// Convert the absolute path to a relative path | ||
relPath, err := filepath.Rel(currentDir, absPath) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to convert to relative path: %w", err) | ||
} | ||
|
||
return relPath, nil | ||
} |
Submodule tui-tgcom
added at
edb05b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters