small performance increase
This commit is contained in:
+21
-53
@@ -1,62 +1,30 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/orus-dev/osui"
|
"github.com/orus-dev/osui"
|
||||||
"github.com/orus-dev/osui/colors"
|
"github.com/orus-dev/osui/ui"
|
||||||
"github.com/orus-dev/osui/ui"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var students []string = []string{}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
screen := osui.NewScreen(App())
|
screen := osui.NewScreen(App())
|
||||||
screen.Run()
|
screen.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func App() *ui.PaginatorComponent {
|
func App() *ui.DivComponent {
|
||||||
w, h := osui.GetTerminalSize()
|
return renderRoot()
|
||||||
|
}
|
||||||
var keybindings ui.Class[*ui.TextComponent]
|
|
||||||
keybindings.SetProperties(func(tc *ui.TextComponent) *ui.TextComponent {
|
func renderRoot() *ui.DivComponent {
|
||||||
tc.Text = colors.Blue + tc.Text
|
var root ui.Id[*ui.DivComponent]
|
||||||
tc.Data.Y = h - 2
|
|
||||||
return tc
|
return root.Id(ui.Div(
|
||||||
})
|
ui.WithPosition(0, 0, ui.Text("student managment system (terminal edition permium) made by fefek")),
|
||||||
|
ui.WithPosition(0, 2, ui.Button("add student")),
|
||||||
return ui.Paginator(
|
ui.WithPosition(25, 2, ui.Button("delete student")),
|
||||||
// Page 1
|
ui.WithPosition(50, 2, ui.Button("info")),
|
||||||
ui.Div(
|
ui.WithPosition(0, 5, ui.Text("students")),
|
||||||
ui.Text("Welcome to the example! The blue text on the bottom show the keybindings"),
|
ui.WithPosition(0, 7, ui.Menu(students...)),
|
||||||
keybindings.Class(ui.Text("Next Page: Tab. Previous Page: shift + tab")),
|
))
|
||||||
),
|
|
||||||
|
|
||||||
// Page 2
|
|
||||||
ui.Div(
|
|
||||||
ui.WithPosition(0, 0, ui.Text("This blue square is a div. A div stores multiple components into one")),
|
|
||||||
ui.WithPosition((w-30)/2, (h-4)/2,
|
|
||||||
ui.WithSize(30, 5,
|
|
||||||
ui.Div(ui.WithPosition(4, 1, ui.Button("Hello, World!").Params(ui.ButtonParams{Width: 19}))).Params(ui.DivParams{Style: ui.DivStyle{Outline: colors.Blue}}),
|
|
||||||
)),
|
|
||||||
keybindings.Class(ui.Text("Navigate: Ctrl+(W/A/S/D)")),
|
|
||||||
),
|
|
||||||
|
|
||||||
// Page 3
|
|
||||||
ui.Div(
|
|
||||||
ui.WithPosition(0, 0, ui.Text("This is a InputBox. It takes user input just like a GUI. "+colors.Red+colors.Bold+"NOTE: This InputBox is inside a div")),
|
|
||||||
ui.WithPosition((w-32)/2, (h-3)/2, ui.InputBox(30)),
|
|
||||||
keybindings.Class(ui.Text("Navigate: Ctrl+(W/A/S/D). Finish: Enter.")),
|
|
||||||
),
|
|
||||||
|
|
||||||
// Page 4
|
|
||||||
ui.Div(
|
|
||||||
ui.WithPosition(0, 0, ui.Text("This is a Button. To click it press Enter. "+colors.Red+colors.Bold+"NOTE: This Button is inside a div")),
|
|
||||||
ui.WithPosition((w-20)/2, (h-3)/2, ui.Button("This is a button")),
|
|
||||||
keybindings.Class(ui.Text("Navigate: Ctrl+(W/A/S/D). Click Button: Enter")),
|
|
||||||
),
|
|
||||||
|
|
||||||
// Page 5
|
|
||||||
ui.Div(
|
|
||||||
ui.WithPosition(0, 0, ui.Text("This is a Menu. It prompts you to select an item. "+colors.Red+colors.Bold+"NOTE: This Menu is inside a div")),
|
|
||||||
ui.WithPosition(0, 2, ui.Menu("Item 1", "Item 2", "Item 3", "Item 4", "Item 5").Params(ui.MenuParams{OnSelected: func(mc *ui.MenuComponent, b bool) {}})),
|
|
||||||
keybindings.Class(ui.Text("Navigate: Ctrl+(W/A/S/D). Navigate Menu: W/S. Select: Enter. Exit Menu: Q. ")),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,13 +14,16 @@ import (
|
|||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RenderLine(frame_, line_ string, x int, fm map[int]string, lm map[int]string) string {
|
var re = regexp.MustCompile(`(\x1b\[([0-9;]*)[a-zA-Z])+`)
|
||||||
|
|
||||||
|
func RenderLine(frame_, line_ string, x int, fm, lm map[int]string) string {
|
||||||
var res strings.Builder
|
var res strings.Builder
|
||||||
frame := []rune(frame_)
|
frame := []rune(frame_)
|
||||||
line := []rune(line_)
|
line := []rune(line_)
|
||||||
|
|
||||||
for i := range frame {
|
flen, llen := len(frame), len(line)
|
||||||
if i >= x && i-x < len(line) {
|
for i := 0; i < flen; i++ {
|
||||||
|
if i >= x && i-x < llen {
|
||||||
if v, ok := lm[i-x]; ok {
|
if v, ok := lm[i-x]; ok {
|
||||||
res.WriteString(v)
|
res.WriteString(v)
|
||||||
}
|
}
|
||||||
@@ -36,8 +39,6 @@ func RenderLine(frame_, line_ string, x int, fm map[int]string, lm map[int]strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CompressString(input string) (string, map[int]string) {
|
func CompressString(input string) (string, map[int]string) {
|
||||||
pattern := `(\x1b\[([0-9;]*)[a-zA-Z])+`
|
|
||||||
re := regexp.MustCompile(pattern)
|
|
||||||
matchesMap := make(map[int]string)
|
matchesMap := make(map[int]string)
|
||||||
res := []rune{}
|
res := []rune{}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user