Skip to content

Commit

Permalink
Fix error message
Browse files Browse the repository at this point in the history
Signed-off-by: Joana Hrotko <[email protected]>
  • Loading branch information
jhrotko committed Mar 11, 2024
1 parent 5d9cdcb commit 42d4678
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cmd/formatter/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (l *logConsumer) write(w io.Writer, container, message string) {
fmt.Fprintf(w, "\033[K%s%s\n", p.prefix, line)
}
}
}, fmt.Errorf("OH NO"))
})

// // save cursor position
// fmt.Print("\0337")
Expand Down
34 changes: 26 additions & 8 deletions cmd/formatter/shortcut.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,43 @@ import (
type LogKeyboard struct {
// mutex sync.Mutex
// message string
err error
err error
started bool
}

var KeyboardInfo = LogKeyboard{}
var errorColor = "\x1b[1;33m"

func (lk *LogKeyboard) PrintKeyboardInfo(print func(), err error) {
func (lk *LogKeyboard) PrintKeyboardInfo(print func()) {
fmt.Print("\033[?25l") // hide cursor
defer fmt.Printf("\033[?25h") // show cursor

lk.err = err
lk.ClearInfo()
if lk.started {
lk.ClearInfo()
} else {
lk.started = true
}
print()
lk.createBuffer()
lk.printInfo()
}

func (lk *LogKeyboard) SError(err string) {
lk.err = fmt.Errorf(err)
}
func (lk *LogKeyboard) Error(err error) {
lk.err = err
}

// This avoids incorrect printing at the end of the terminal
func (lk *LogKeyboard) createBuffer() {
fmt.Print("\012") // new line
fmt.Print("\012")
fmt.Print("\033[2A") // go back 3 lines
}

func (lk *LogKeyboard) printInfo() {
height := goterm.Height()

fmt.Print("\0337") // save cursor position
if lk.err != nil {
fmt.Printf("\033[%d;0H", height-1) // Move to before last line
Expand All @@ -40,14 +59,13 @@ func (lk *LogKeyboard) printInfo() {

func (lk *LogKeyboard) ClearInfo() {
height := goterm.Height()

fmt.Print("\0337") // save cursor position
if lk.err != nil {
fmt.Printf("\033[%d;0H", height-1)
fmt.Print("\033[0K") // clear line
fmt.Print("\033[2K") // clear line
}
fmt.Printf("\033[%d;0H", height) // Move to last line
fmt.Print("\033[0K") // clear line
fmt.Print("\033[2K") // clear line
fmt.Print("\0338") // restore cursor position
}

Expand Down
24 changes: 8 additions & 16 deletions pkg/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/docker/compose/v2/pkg/progress"
"github.com/eiannone/keyboard"
"github.com/hashicorp/go-multierror"
"github.com/skratchdot/open-golang/open"
)

func (s *composeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error { //nolint:gocyclo
Expand Down Expand Up @@ -103,25 +104,16 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
gracefulTeardown()
case keyboard.KeyCtrlG:
link := fmt.Sprintf("docker-desktop://dashboard/apps/%s", project.Name)
// err := fmt.Errorf("OH NO!\n")
// if err != nil {
// fmt.Print("\0337") // save cursor position
// fmt.Println("\033[0;0H") // Move to top
// fmt.Printf("\033[0;34m") //change color
// fmt.Printf("\033[%d;0H", goterm.Height()-1) // Move to last line
// fmt.Printf("\033[K%s", err.Error())
// // fmt.Println("\033[0m") // restore color
// fmt.Println("\033[u") //restore
// }
// err := open.Run(link)
fmt.Println("link: ", link)
// if err != nil {
// fmt.Fprintln(s.stdinfo(), "Could not open Docker Desktop")
// }
err := open.Run(link)
if err != nil {
formatter.KeyboardInfo.SError("Could not open Docker Desktop")
} else {
formatter.KeyboardInfo.Error(nil)
}
case keyboard.KeyEnter:
formatter.KeyboardInfo.PrintEnter()
default:
if key != 0 {
if key != 0 { // If some key is pressed
fmt.Println("key pressed: ", key)
}
}
Expand Down

0 comments on commit 42d4678

Please sign in to comment.