Skip to content

Commit

Permalink
import new mist (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
thatstoasty authored Jul 4, 2024
1 parent 892272b commit 348f2b3
Show file tree
Hide file tree
Showing 16 changed files with 547 additions and 634 deletions.
12 changes: 6 additions & 6 deletions benchmarks/basic_styling.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ fn basic_styling():
var style = (
mog.new_style()
.bold(True)
.foreground(mog.Color("#FAFAFA"))
.background(mog.Color("#7D56F4"))
.foreground(mog.Color(0xFAFAFA))
.background(mog.Color(0x7D56F4))
.padding_top(2)
.padding_left(4)
.width(22)
Expand All @@ -20,8 +20,8 @@ fn basic_styling():
var file_style = (
mog.new_style()
.bold(True)
.foreground(mog.Color("#FAFAFA"))
.background(mog.Color("#7D56F4"))
.foreground(mog.Color(0xFAFAFA))
.background(mog.Color(0x7D56F4))
.padding_top(2)
.padding_left(4)
.width(22)
Expand All @@ -38,8 +38,8 @@ fn basic_styling_big_file():
try:
with open("./benchmarks/data/big.txt", "r") as file:
content = file.read()
var style = mog.new_style().bold(True).foreground(mog.Color("#FAFAFA")).background(
mog.Color("#7D56F4")
var style = mog.new_style().bold(True).foreground(mog.Color(0xFAFAFA)).background(
mog.Color(0x7D56F4)
).width(100)
var output = style.render(content)
keep(output)
Expand Down
30 changes: 15 additions & 15 deletions benchmarks/layout.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import mog

alias width = 96
alias column_width = 30
alias subtle = mog.AdaptiveColor(light="#D9DCCF", dark="#383838")
alias highlight = mog.AdaptiveColor(light="#874BFD", dark="#7D56F4")
alias special = mog.AdaptiveColor(light="#43BF6D", dark="#73F59F")
alias subtle = mog.AdaptiveColor(light=0xD9DCCF, dark=0x383838)
alias highlight = mog.AdaptiveColor(light=0x874BFD, dark=0x7D56F4)
alias special = mog.AdaptiveColor(light=0x43BF6D, dark=0x73F59F)


fn build_tabs() -> String:
Expand Down Expand Up @@ -79,16 +79,16 @@ fn build_description() -> String:

fn build_dialog_box() -> String:
var dialog_box_style = mog.new_style().alignment(position.center).border(rounded_border()).border_foreground(
mog.Color("#874BFD")
mog.Color(0x874BFD)
).padding(1, 0)

var button_style = mog.new_style().foreground(mog.Color("#FFF7DB")).background(mog.Color("#888B7E")).padding(
var button_style = mog.new_style().foreground(mog.Color(0xFFF7DB)).background(mog.Color(0x888B7E)).padding(
0, 3
).margin_top(1)

var active_button_style = button_style.foreground(mog.Color("#FFF7DB")).background(
mog.Color("#F25D94")
).margin_right(2).underline()
var active_button_style = button_style.foreground(mog.Color(0xFFF7DB)).background(mog.Color(0xF25D94)).margin_right(
2
).underline()

var ok_button = active_button_style.render("Yes")
var cancel_button = button_style.render("Maybe")
Expand Down Expand Up @@ -125,7 +125,7 @@ fn build_lists() -> String:

var check_mark = mog.new_style().foreground(special).padding_right(1).render("")

var list_done = mog.new_style().crossout().foreground(mog.AdaptiveColor(light="#969B86", dark="#696969"))
var list_done = mog.new_style().crossout().foreground(mog.AdaptiveColor(light=0x969B86, dark=0x696969))

var lists = join_horizontal(
position.top,
Expand Down Expand Up @@ -170,7 +170,7 @@ fn build_lists() -> String:
fn build_history() -> String:
var history_style = mog.new_style().height(20).width(column_width).padding(1, 2).margin(1, 3, 0, 0).alignment(
position.left
).foreground(mog.Color("#FFFDF5")).background(highlight)
).foreground(mog.Color(0xFFFDF5)).background(highlight)

alias history_a = "The Romans learned from the Greeks that quinces slowly cooked with honey would “set” when cool. The Apicius gives a recipe for preserving whole quinces, stems and leaves attached, in a bath of honey diluted with defrutum: Roman marmalade. Preserves of quince and lemon appear (along with rose, apple, plum and pear) in the Book of ceremonies of the Byzantine Emperor Constantine VII Porphyrogennetos."
alias history_b = "Medieval quince preserves, which went by the French name cotignac, produced in a clear version and a fruit pulp version, began to lose their medieval seasoning of spices in the 16th century. In the 17th century, La Varenne provided recipes for both thick and clear cotignac."
Expand All @@ -185,17 +185,17 @@ fn build_history() -> String:


fn build_status_bar() -> String:
var status_nugget_style = mog.new_style().foreground(mog.Color("#FFFDF5")).padding(0, 1)
var status_nugget_style = mog.new_style().foreground(mog.Color(0xFFFDF5)).padding(0, 1)

var status_bar_style = mog.new_style().foreground(mog.Color("#C1C6B2")).background(mog.Color("#353533"))
var status_bar_style = mog.new_style().foreground(mog.Color(0xC1C6B2)).background(mog.Color(0x353533))

var status_style = mog.new_style().foreground(mog.Color("#FFFDF5")).background(mog.Color("#FF5F87")).padding(0, 1)
var status_style = mog.new_style().foreground(mog.Color(0xFFFDF5)).background(mog.Color(0xFF5F87)).padding(0, 1)
# .margin_right(1)

var encoding_style = status_nugget_style.background(mog.Color("#A550DF")).horizontal_alignment(position.right)
var encoding_style = status_nugget_style.background(mog.Color(0xA550DF)).horizontal_alignment(position.right)

var status_text_style = status_bar_style.padding_left(1)
var fish_cake_style = status_nugget_style.background(mog.Color("#6124DF"))
var fish_cake_style = status_nugget_style.background(mog.Color(0x6124DF))

var status_key = status_style.render("STATUS")
var encoding = encoding_style.render("UTF-8")
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/run.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import mog


var style = mog.new_style().horizontal_alignment(mog.center).vertical_alignment(mog.center).padding(0, 1)
var header_style = style.foreground(mog.Color("#39E506"))
var header_style = style.foreground(mog.Color(0x39E506))


fn table_styling(row: Int, col: Int) -> mog.Style:
Expand Down
4 changes: 2 additions & 2 deletions examples/readme/basic.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ fn main():
var style = (
mog.new_style()
.bold(True)
.foreground(mog.Color("#FAFAFA"))
.background(mog.Color("#7D56F4"))
.foreground(mog.Color(0xFAFAFA))
.background(mog.Color(0x7D56F4))
.padding_top(2)
.padding_left(4)
.width(22)
Expand Down
30 changes: 15 additions & 15 deletions examples/readme/layout.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import mog

alias width = 96
alias column_width = 30
alias subtle = mog.AdaptiveColor(light="#D9DCCF", dark="#383838")
alias highlight = mog.AdaptiveColor(light="#874BFD", dark="#7D56F4")
alias special = mog.AdaptiveColor(light="#43BF6D", dark="#73F59F")
alias subtle = mog.AdaptiveColor(light=0xD9DCCF, dark=0x383838)
alias highlight = mog.AdaptiveColor(light=0x874BFD, dark=0x7D56F4)
alias special = mog.AdaptiveColor(light=0x43BF6D, dark=0x73F59F)


fn build_tabs() -> String:
Expand Down Expand Up @@ -75,16 +75,16 @@ fn build_description() -> String:

fn build_dialog_box() -> String:
var dialog_box_style = mog.new_style().alignment(position.center).border(rounded_border()).border_foreground(
mog.Color("#874BFD")
mog.Color(0x874BFD)
).padding(1, 0)

var button_style = mog.new_style().foreground(mog.Color("#FFF7DB")).background(mog.Color("#888B7E")).padding(
var button_style = mog.new_style().foreground(mog.Color(0xFFF7DB)).background(mog.Color(0x888B7E)).padding(
0, 3
).margin_top(1)

var active_button_style = button_style.foreground(mog.Color("#FFF7DB")).background(
mog.Color("#F25D94")
).margin_right(2).underline()
var active_button_style = button_style.foreground(mog.Color(0xFFF7DB)).background(mog.Color(0xF25D94)).margin_right(
2
).underline()

var ok_button = active_button_style.render("Yes")
var cancel_button = button_style.render("Maybe")
Expand Down Expand Up @@ -121,7 +121,7 @@ fn build_lists() -> String:

var check_mark = mog.new_style().foreground(special).padding_right(1).render("")

var list_done = mog.new_style().crossout().foreground(mog.AdaptiveColor(light="#969B86", dark="#696969"))
var list_done = mog.new_style().crossout().foreground(mog.AdaptiveColor(light=0x969B86, dark=0x696969))

var lists = join_horizontal(
position.top,
Expand Down Expand Up @@ -166,7 +166,7 @@ fn build_lists() -> String:
fn build_history() -> String:
var history_style = mog.new_style().height(20).width(column_width).padding(1, 2).margin(1, 3, 0, 0).alignment(
position.left
).foreground(mog.Color("#FFFDF5")).background(highlight)
).foreground(mog.Color(0xFFFDF5)).background(highlight)

alias history_a = "The Romans learned from the Greeks that quinces slowly cooked with honey would “set” when cool. The Apicius gives a recipe for preserving whole quinces, stems and leaves attached, in a bath of honey diluted with defrutum: Roman marmalade. Preserves of quince and lemon appear (along with rose, apple, plum and pear) in the Book of ceremonies of the Byzantine Emperor Constantine VII Porphyrogennetos."
alias history_b = "Medieval quince preserves, which went by the French name cotignac, produced in a clear version and a fruit pulp version, began to lose their medieval seasoning of spices in the 16th century. In the 17th century, La Varenne provided recipes for both thick and clear cotignac."
Expand All @@ -181,17 +181,17 @@ fn build_history() -> String:


fn build_status_bar() -> String:
var status_nugget_style = mog.new_style().foreground(mog.Color("#FFFDF5")).padding(0, 1)
var status_nugget_style = mog.new_style().foreground(mog.Color(0xFFFDF5)).padding(0, 1)

var status_bar_style = mog.new_style().foreground(mog.Color("#C1C6B2")).background(mog.Color("#353533"))
var status_bar_style = mog.new_style().foreground(mog.Color(0xC1C6B2)).background(mog.Color(0x353533))

var status_style = mog.new_style().foreground(mog.Color("#FFFDF5")).background(mog.Color("#FF5F87")).padding(0, 1)
var status_style = mog.new_style().foreground(mog.Color(0xFFFDF5)).background(mog.Color(0xFF5F87)).padding(0, 1)
# .margin_right(1)

var encoding_style = status_nugget_style.background(mog.Color("#A550DF")).horizontal_alignment(position.right)
var encoding_style = status_nugget_style.background(mog.Color(0xA550DF)).horizontal_alignment(position.right)

var status_text_style = status_bar_style.padding_left(1)
var fish_cake_style = status_nugget_style.background(mog.Color("#6124DF"))
var fish_cake_style = status_nugget_style.background(mog.Color(0x6124DF))

var status_key = status_style.render("STATUS")
var encoding = encoding_style.render("UTF-8")
Expand Down
2 changes: 1 addition & 1 deletion examples/table/ansi.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import mog


fn main():
var s = mog.new_style().foreground(mog.Color("240"))
var s = mog.new_style().foreground(mog.Color(240))

var t = mog.new_table()
t.width = 50
Expand Down
62 changes: 31 additions & 31 deletions examples/table/pokemon.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

# fn build_color_mapping() -> Dict[mog.Color]:
# var type_colors = Dict[mog.Color]()
# type_colors.put("Bug", mog.Color("#D7FF87"))
# type_colors.put("Electric", mog.Color("#FDFF90"))
# type_colors.put("Fire", mog.Color("#FF7698"))
# type_colors.put("Flying", mog.Color("#FF87D7"))
# type_colors.put("Grass", mog.Color("#75FBAB"))
# type_colors.put("Ground", mog.Color("#FF875F"))
# type_colors.put("Normal", mog.Color("#929292"))
# type_colors.put("Poison", mog.Color("#7D5AFC"))
# type_colors.put("Water", mog.Color("#00E2C7"))
# type_colors.put("Bug", mog.Color(0xD7FF87))
# type_colors.put("Electric", mog.Color(0xFDFF90))
# type_colors.put("Fire", mog.Color(0xFF7698))
# type_colors.put("Flying", mog.Color(0xFF87D7))
# type_colors.put("Grass", mog.Color(0x75FBAB))
# type_colors.put("Ground", mog.Color(0xFF875F))
# type_colors.put("Normal", mog.Color(0x929292))
# type_colors.put("Poison", mog.Color(0x7D5AFC))
# type_colors.put("Water", mog.Color(0x00E2C7))

# return type_colors

Expand All @@ -24,15 +24,15 @@

# fn build_dim_color_mapping() -> Dict[mog.Color]:
# var dim_type_colors = Dict[mog.Color]()
# dim_type_colors.put("Bug", mog.Color("#97AD64"))
# dim_type_colors.put("Electric", mog.Color("#FCFF5F"))
# dim_type_colors.put("Fire", mog.Color("#BA5F75"))
# dim_type_colors.put("Flying", mog.Color("#C97AB2"))
# dim_type_colors.put("Grass", mog.Color("#59B980"))
# dim_type_colors.put("Ground", mog.Color("#C77252"))
# dim_type_colors.put("Normal", mog.Color("#727272"))
# dim_type_colors.put("Poison", mog.Color("#634BD0"))
# dim_type_colors.put("Water", mog.Color("#439F8E"))
# dim_type_colors.put("Bug", mog.Color(0x97AD64))
# dim_type_colors.put("Electric", mog.Color(0xFCFF5F))
# dim_type_colors.put("Fire", mog.Color(0xBA5F75))
# dim_type_colors.put("Flying", mog.Color(0xC97AB2))
# dim_type_colors.put("Grass", mog.Color(0x59B980))
# dim_type_colors.put("Ground", mog.Color(0xC77252))
# dim_type_colors.put("Normal", mog.Color(0x727272))
# dim_type_colors.put("Poison", mog.Color(0x634BD0))
# dim_type_colors.put("Water", mog.Color(0x439F8E))

# return dim_type_colors

Expand Down Expand Up @@ -77,15 +77,15 @@
# # if is_even:
# # colors = DIM_TYPE_COLORS

# # var color = colors.get(data[row - 1][col], mog.Color("#FFFFFF"))
# # var color = colors.get(data[row - 1][col], mog.Color(0xFFFFFF))
# # var copy_style = style.foreground(color)
# # return copy_style

# # if is_even:
# # var copy_style = style.foreground(mog.Color("245"))
# # var copy_style = style.foreground(mog.Color("245))
# # return copy_style

# # var copy_style = style.foreground(mog.Color("252"))
# # var copy_style = style.foreground(mog.Color("252))
# # return copy_style
# # return style_func

Expand All @@ -98,12 +98,12 @@
# # .padding_left(1)

# # var header_style = style \
# # .foreground(mog.Color("252")) \
# # .foreground(mog.Color("252)) \
# # .bold()

# # var selected_style = style \
# # .foreground(mog.Color("#01BE85")) \
# # .background(mog.Color("#00432F"))
# # .foreground(mog.Color(0x01BE85)) \
# # .background(mog.Color(0x00432F))

# @always_inline
# fn capitalize_headers(data: List[String]) -> List[String]:
Expand All @@ -122,12 +122,12 @@
# .padding_left(1)

# var header_style = style \
# .foreground(mog.Color("252")) \
# .foreground(mog.Color("252)) \
# .bold()

# var selected_style = style \
# .foreground(mog.Color("#01BE85")) \
# .background(mog.Color("#00432F"))
# .foreground(mog.Color(0x01BE85)) \
# .background(mog.Color(0x00432F))

# if row == 0:
# return header_style
Expand All @@ -141,19 +141,19 @@
# if is_even:
# colors = DIM_TYPE_COLORS

# var color = colors.get(data[row - 1][col], mog.Color("#FFFFFF"))
# var color = colors.get(data[row - 1][col], mog.Color(0xFFFFFF))
# var copy_style = style.foreground(color)
# return copy_style

# if is_even:
# var copy_style = style.foreground(mog.Color("245"))
# var copy_style = style.foreground(mog.Color("245))
# return copy_style

# var copy_style = style.foreground(mog.Color("252"))
# var copy_style = style.foreground(mog.Color("252))
# return copy_style

# var border_style = mog.Style()
# border_style = border_style.foreground(mog.Color("238"))
# border_style = border_style.foreground(mog.Color("238))
# var table = mog.new_table()
# table.rows(data)
# table.width = 100
Expand Down
Loading

0 comments on commit 348f2b3

Please sign in to comment.