Skip to content

Commit

Permalink
💄 Increase app width from 70 to 80 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
beskay committed Feb 28, 2024
1 parent 36dbd82 commit 80bf845
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
25 changes: 13 additions & 12 deletions internal/tui/leaderboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package tui

import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/ethernautdao/evm-runners-cli/internal/utils"
"strings"
"time"

tea "github.com/charmbracelet/bubbletea"
"github.com/ethernautdao/evm-runners-cli/internal/utils"
)

type LeaderboardUI struct {
Expand All @@ -32,7 +33,7 @@ func NewLeaderboardUI(submissions []utils.SubmissionData, field string) (*Leader
func leaderboardTable(submissions []utils.SubmissionData, field string) string {
var sb strings.Builder

tableWidth := 65
tableWidth := 75

if len(submissions) > 0 {

Expand All @@ -44,7 +45,7 @@ func leaderboardTable(submissions []utils.SubmissionData, field string) string {
}

headline := "\x1b[1m" + headlineText + "\x1b[0m" + "\n\n"
header := fmt.Sprintf("\x1b[90m│\x1b[0m #\t%-18s%-12s%-18s%-10s\x1b[90m│\x1b[0m\n", "USER", strings.ToUpper(field), "DATE", "TYPE")
header := fmt.Sprintf("\x1b[90m│\x1b[0m #\t%-22s%-14s%-20s%-12s\x1b[90m│\x1b[0m\n", "USER", strings.ToUpper(field), "DATE", "TYPE")
separator := "\x1b[90m" + "│" + strings.Repeat("─", tableWidth) + "│" + "\n" + "\x1b[0m"

// Calculate padding for the headline
Expand All @@ -68,13 +69,13 @@ func leaderboardTable(submissions []utils.SubmissionData, field string) string {
for i, submission := range submissions {
userStr := fmt.Sprintf("%s", submission.Username)

// Check if the userStr is longer than 16 characters
if len(userStr) > 16 {
// Truncate the userStr to 16 characters
userStr = userStr[:16]
// Check if the userStr is longer than 20 characters
if len(userStr) > 20 {
// Truncate the userStr to 20 characters
userStr = userStr[:20]

// Replace the last three characters with "..."
userStr = userStr[:13] + "..."
// Replace the last two characters with ".."
userStr = userStr[:18] + ".."
}

// Convert the date string to a time.Time object and format it
Expand All @@ -85,9 +86,9 @@ func leaderboardTable(submissions []utils.SubmissionData, field string) string {
dateStr := date.Format(displayLayout)

if field == "gas" {
sb.WriteString(fmt.Sprintf("\x1b[90m│\x1b[0m %d\t%-18s%-12s%-18s%-10s\x1b[90m│\x1b[0m\n", i+1, userStr, submission.Gas, dateStr, submission.Type))
sb.WriteString(fmt.Sprintf("\x1b[90m│\x1b[0m %d\t%-22s%-14s%-20s%-12s\x1b[90m│\x1b[0m\n", i+1, userStr, submission.Gas, dateStr, submission.Type))
} else if field == "size" {
sb.WriteString(fmt.Sprintf("\x1b[90m│\x1b[0m %d\t%-18s%-12s%-18s%-10s\x1b[90m│\x1b[0m\n", i+1, userStr, submission.Size, dateStr, submission.Type))
sb.WriteString(fmt.Sprintf("\x1b[90m│\x1b[0m %d\t%-22s%-14s%-20s%-12s\x1b[90m│\x1b[0m\n", i+1, userStr, submission.Size, dateStr, submission.Type))
}
}

Expand Down
11 changes: 6 additions & 5 deletions internal/tui/listLevels.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package tui

import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/ethernautdao/evm-runners-cli/internal/utils"
"sort"
"strings"

tea "github.com/charmbracelet/bubbletea"
"github.com/ethernautdao/evm-runners-cli/internal/utils"
)

type levelListModel struct {
Expand Down Expand Up @@ -64,14 +65,14 @@ func (m *levelListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m *levelListModel) View() string {
var sb strings.Builder

tableWidth := 65
tableWidth := 75

if m.Done {
return ""
} else {
sb.WriteString("\x1b[90m┌" + strings.Repeat("─", tableWidth) + "┐\n\x1b[0m") // Top border of the box

header := fmt.Sprintf("\x1b[90m│\x1b[0m #\t%-16s%-12s%-12s%-18s\x1b[90m│\x1b[0m\n", "NAME", "SOLVES", "SOLVED", "TYPE")
header := fmt.Sprintf("\x1b[90m│\x1b[0m #\t%-20s%-14s%-14s%-20s\x1b[90m│\x1b[0m\n", "NAME", "SOLVES", "SOLVED", "TYPE")
separator := "\x1b[90m" + "│" + strings.Repeat("─", tableWidth) + "│" + "\n" + "\x1b[0m"

sb.WriteString(header)
Expand All @@ -84,7 +85,7 @@ func (m *levelListModel) View() string {
} else {
sb.WriteString("\x1b[90m│\x1b[0m ")
}
sb.WriteString(fmt.Sprintf("%s\t%-16s%-12s%-12s%-18s\x1b[90m│\x1b[0m\n", l.ID, strings.ToLower(l.Contract), m.solves[l.Contract], m.submissions[l.Contract], l.Type))
sb.WriteString(fmt.Sprintf("%s\t%-20s%-14s%-14s%-20s\x1b[90m│\x1b[0m\n", l.ID, strings.ToLower(l.Contract), m.solves[l.Contract], m.submissions[l.Contract], l.Type))
if m.Cursor == i && m.descriptionShown {
descriptionLines := strings.Split(l.Description, "\n")
separator := "\x1b[90m" + "│" + strings.Repeat("-", tableWidth) + "│" + "\n" + "\x1b[0m"
Expand Down
17 changes: 7 additions & 10 deletions internal/utils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"golang.org/x/crypto/ssh/terminal"
"io"
"math/rand"
"net/http"
Expand All @@ -15,6 +14,8 @@ import (
"strconv"
"strings"
"time"

"golang.org/x/term"
)

const (
Expand Down Expand Up @@ -43,7 +44,7 @@ func RunTest(levelsDir string, testContract string, verbose bool) ([]byte, error
bytes := make([]byte, 20)
_, err := rand.Read(bytes)
if err != nil {
// Handle error
bytes = []byte("12345678901234567890")
}
randAddress := "0x" + hex.EncodeToString(bytes)

Expand All @@ -55,7 +56,7 @@ func RunTest(levelsDir string, testContract string, verbose bool) ([]byte, error
bytes = make([]byte, 32)
_, err = rand.Read(bytes)
if err != nil {
// Handle error
bytes = []byte("12345678901234567890123456789012")
}
randPrevRandao := "0x" + hex.EncodeToString(bytes)

Expand Down Expand Up @@ -199,8 +200,6 @@ func ParseOutput(output string) (int, int, error) {
if err != nil {
return 0, 0, fmt.Errorf("error converting to int: %v", err)
}
} else {
//fmt.Println("No matching value found")
}
}
if strings.Contains(line, "Contract size:") {
Expand All @@ -212,8 +211,6 @@ func ParseOutput(output string) (int, int, error) {
if err != nil {
return 0, 0, fmt.Errorf("error converting to int: %v", err)
}
} else {
//fmt.Println("No matching value found")
}
}
}
Expand All @@ -228,7 +225,7 @@ func GetBytecodeToValidate(bytecode string, level string, filename string, level
return "", "", nil
}

// check if bytecode was provided, if compile the source code
// check if bytecode was provided, if yes compile the source code
if bytecode != "" {
// check if bytecode is valid
bytecode, err := sanitizeBytecode(bytecode)
Expand Down Expand Up @@ -434,12 +431,12 @@ func sanitizeBytecode(bytecode string) (string, error) {
}

func CheckMinTerminalWidth() error {
width, _, err := terminal.GetSize(int(os.Stdout.Fd()))
width, _, err := term.GetSize(int(os.Stdout.Fd()))
if err != nil {
return fmt.Errorf("error getting terminal size: %v", err)
}

minTerminalWidth := 70
minTerminalWidth := 80
if width < minTerminalWidth {
return fmt.Errorf("Terminal width is too small (%d < %d).\nPlease resize your terminal window.\n", width, minTerminalWidth)
}
Expand Down

0 comments on commit 80bf845

Please sign in to comment.