diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index baee989..d141180 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,7 @@ name: Run Tests -on: ["push"] +on: + pull_request: jobs: test: diff --git a/README.md b/README.md index 10ef6c1..7dbc532 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,9 @@ Users familiar with CSS will feel at home with Mog. ```mojo -from mog import Style +import mog -var style = Style.new() \ +var style = mog.new_style() \ .bold(True) \ .foreground(mog.Color("#FAFAFA")) \ .background(mog.Color("#7D56F4")) \ @@ -110,7 +110,7 @@ mog.CompleteAdaptiveColor( Mog supports the usual ANSI text formatting options: ```mojo -var style = Style.new() \ +var style = mog.new_style() \ .bold(True) \ .italic(True) \ .faint(True) \ @@ -126,14 +126,14 @@ Mog also supports rules for block-level formatting: ```mojo # Padding -var style = Style.new() \ +var style = mog.new_style() \ .padding_top(2) \ .padding_right(4) \ .padding_bottom(2) \ .padding_left(4) # Margins -var style = Style.new() \ +var style = mog.new_style() \ .margin_top(2) \ .margin_right(4) \ .margin_bottom(2) \ @@ -145,17 +145,17 @@ format as CSS: ```mojo # 2 cells on all sides -Style.new().padding(2) +mog.new_style().padding(2) # 2 cells on the top and bottom, 4 cells on the left and right -Style.new().margin(2, 4) +mog.new_style().margin(2, 4) # 1 cell on the top, 4 cells on the sides, 2 cells on the bottom -Style.new().padding(1, 4, 2) +mog.new_style().padding(1, 4, 2) # Clockwise, starting from the top: 2 cells on the top, 4 on the right, 3 on # the bottom, and 1 on the left -Style.new().margin(2, 4, 3, 1) +mog.new_style().margin(2, 4, 3, 1) ``` ## Aligning Text @@ -163,7 +163,7 @@ Style.new().margin(2, 4, 3, 1) You can align paragraphs of text to the left, right, or center. ```mojo -var style = Style.new() \ +var style = mog.new_style() \ .width(24) \ .align(position.left) \ # align it left .align(position.right) \ # no wait, align it right @@ -175,7 +175,7 @@ var style = Style.new() \ Setting a minimum width and height is simple and straightforward. ```mojo -var style = Style.new() \ +var style = mog.new_style() \ .set_string("What’s for lunch?") \ .width(24) \ .height(32) \ @@ -188,12 +188,12 @@ Adding borders is easy: ```mojo # Add a purple, rectangular border -var style = Style.new() \ +var style = mog.new_style() \ .border(normal_border()) \ .border_foreground(mog.Color("63")) # Set a rounded, yellow-on-purple border to the top and left -var another_style = Style.new() \ +var another_style = mog.new_style() \ .border(rounded_border()) \ .border_foreground(mog.Color("228")) \ .border_background(mog.Color("63")) \ @@ -218,11 +218,11 @@ pattern to the margin and padding shorthand functions. ```mojo # Add a thick border to the top and bottom -Style.new().border(thick_border(), True, False) +mog.new_style().border(thick_border(), True, False) # Add a double border to the top and left sides. Rules are set clockwise # from top. -Style.new().border(double_border(), True, False, False, True) +mog.new_style().border(double_border(), True, False, False, True) ``` ## Copying Styles @@ -230,7 +230,7 @@ Style.new().border(double_border(), True, False, False, True) Just use `copy()`: ```mojo -var style = Style.new().foreground(mog.Color("219")) +var style = mog.new_style().foreground(mog.Color("219")) var wild_style = style.copy().blink(True) ``` @@ -244,7 +244,7 @@ styles. All rules can be unset: ```mojo -var style = Style.new() \ +var style = mog.new_style() \ .bold(True) \ # make it bold .unset_bold() \ # jk don't make it bold .background(mog.Color("227")) \ # yellow background @@ -278,7 +278,7 @@ tabs to 4 spaces at render time. This behavior can be changed on a per-style basis, however: ```mojo -style = Style.new() # tabs will render as 4 spaces, the default +style = mog.new_style() # tabs will render as 4 spaces, the default style = style.tab_width(2) # render tabs as 2 spaces style = style.tab_width(0) # remove tabs entirely style = style.tab_width(mog.NO_TAB_CONVERSION) # leave tabs intact @@ -289,7 +289,7 @@ style = style.tab_width(mog.NO_TAB_CONVERSION) # leave tabs intact Generally, you just call the `render(string)` method on a `mog.Style`: ```mojo -style = Style.new().bold(True).set_string("Hello,") +style = mog.new_style().bold(True).set_string("Hello,") print(style.render("kitty.")) # Hello, kitty. print(style.render("puppy.")) # Hello, puppy. print(style.render("my", "puppy.")) # Hello, my puppy. @@ -298,7 +298,7 @@ print(style.render("my", "puppy.")) # Hello, my puppy. But you could also use the Stringer interface: ```mojo -var style = Style.new().set_string("你好,猫咪。").bold(True) +var style = mog.new_style().set_string("你好,猫咪。").bold(True) print(style) # 你好,猫咪。 ``` @@ -350,7 +350,7 @@ your layouts. ```mojo # render a block of text. -var style = Style.new() \ +var style = mog.new_style() \ .width(40) \ .padding(2) var block string = style.render(some_long_string) @@ -407,7 +407,7 @@ Use the table package to style and render the table. ```mojo t = table.new_table(). .border(normal_border()) \ - .border_style(Style.new().foreground(mog.Color("99"))) \ + .border_style(mog.new_style().foreground(mog.Color("99"))) \ .headers("LANGUAGE", "FORMAL", "INFORMAL") \ .rows(rows) diff --git a/examples/readme/basic.mojo b/examples/readme/basic.mojo index ffe3b43..d8da2cc 100644 --- a/examples/readme/basic.mojo +++ b/examples/readme/basic.mojo @@ -3,7 +3,7 @@ import mog var style = ( - Style.new() + mog.new_style() .bold(True) .foreground(mog.Color("#FAFAFA")) .background(mog.Color("#7D56F4")) @@ -15,7 +15,7 @@ var style = ( fn main() raises: # var style = ( - # Style.new() + # mog.new_style() # .bold(True) # .foreground(mog.Color("#FAFAFA")) # .background(mog.Color("#7D56F4")) diff --git a/examples/readme/layout.mojo b/examples/readme/layout.mojo index 1c23c4b..2ae3926 100644 --- a/examples/readme/layout.mojo +++ b/examples/readme/layout.mojo @@ -43,7 +43,7 @@ fn build_tabs() -> String: bottom_right="┴", ) - var tab_style = Style.new().border(tab_border).border_foreground(highlight).padding(0, 1) + var tab_style = mog.new_style().border(tab_border).border_foreground(highlight).padding(0, 1) var active_tab = tab_style.copy().border(active_tab_border, True) @@ -62,11 +62,11 @@ fn build_tabs() -> String: fn build_description() -> String: - var divider = Style.new().padding(0, 1).foreground(subtle).render("•") + var divider = mog.new_style().padding(0, 1).foreground(subtle).render("•") - var url = Style.new().foreground(special) - var desc_style = Style.new().margin_top(1) - var info_style = Style.new().border(normal_border(), True, False, False, False).border_foreground(subtle) + var url = mog.new_style().foreground(special) + var desc_style = mog.new_style().margin_top(1) + var info_style = mog.new_style().border(normal_border(), True, False, False, False).border_foreground(subtle) return join_vertical( position.left, @@ -76,11 +76,11 @@ fn build_description() -> String: fn build_dialog_box() -> String: - var dialog_box_style = Style.new().alignment(position.center).border(rounded_border()).border_foreground( + var dialog_box_style = mog.new_style().alignment(position.center).border(rounded_border()).border_foreground( mog.Color("#874BFD") ).padding(1, 0) - var button_style = Style.new().foreground(mog.Color("#FFF7DB")).background(mog.Color("#888B7E")).padding( + var button_style = mog.new_style().foreground(mog.Color("#FFF7DB")).background(mog.Color("#888B7E")).padding( 0, 3 ).margin_top(1) @@ -91,7 +91,9 @@ fn build_dialog_box() -> String: var ok_button = active_button_style.render("Yes") var cancel_button = button_style.render("Maybe") - var question = Style.new().width(50).alignment(position.center).render("Are you sure you want to eat marmalade?") + var question = mog.new_style().width(50).alignment(position.center).render( + "Are you sure you want to eat marmalade?" + ) var buttons = join_horizontal(position.top, ok_button, cancel_button) var ui = join_vertical(position.center, question, buttons) @@ -109,19 +111,19 @@ fn build_dialog_box() -> String: fn build_lists() -> String: - var list_style = Style.new().border(normal_border(), False, True, False, False).border_foreground( + var list_style = mog.new_style().border(normal_border(), False, True, False, False).border_foreground( subtle ).margin_right(2).height(8).width(column_width + 1) - var list_header = Style.new().border(normal_border(), False, False, True, False).border_foreground( + var list_header = mog.new_style().border(normal_border(), False, False, True, False).border_foreground( subtle ).margin_right(2) - var list_item = Style.new().padding_left(2) + var list_item = mog.new_style().padding_left(2) - var check_mark = Style.new().foreground(special).padding_right(1).render("✔") + var check_mark = mog.new_style().foreground(special).padding_right(1).render("✔") - var list_done = Style.new().crossout().foreground(mog.AdaptiveColor(light="#969B86", dark="#696969")) + var list_done = mog.new_style().crossout().foreground(mog.AdaptiveColor(light="#969B86", dark="#696969")) var lists = join_horizontal( position.top, @@ -168,7 +170,7 @@ fn build_lists() -> String: fn build_history() -> String: - var history_style = Style.new().height(20).width(column_width).padding(1, 2).margin(1, 3, 0, 0).alignment( + 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) @@ -185,11 +187,11 @@ fn build_history() -> String: fn build_status_bar() -> String: - var status_nugget_style = Style.new().foreground(mog.Color("#FFFDF5")).padding(0, 1) + var status_nugget_style = mog.new_style().foreground(mog.Color("#FFFDF5")).padding(0, 1) - var status_bar_style = Style.new().foreground(mog.Color("#C1C6B2")).background(mog.Color("#353533")) + var status_bar_style = mog.new_style().foreground(mog.Color("#C1C6B2")).background(mog.Color("#353533")) - var status_style = Style.new().foreground(mog.Color("#FFFDF5")).background(mog.Color("#FF5F87")).padding(0, 1) + var status_style = mog.new_style().foreground(mog.Color("#FFFDF5")).background(mog.Color("#FF5F87")).padding(0, 1) # .margin_right(1) var encoding_style = status_nugget_style.copy().background(mog.Color("#A550DF")).horizontal_alignment( @@ -220,7 +222,7 @@ fn build_status_bar() -> String: fn main(): # The page style var builder = StringBuilder() - var doc_style = Style.new().padding(1, 2, 1, 2).border(rounded_border()).border_foreground(subtle) + var doc_style = mog.new_style().padding(1, 2, 1, 2).border(rounded_border()).border_foreground(subtle) # Tabs. _ = builder.write_string(build_tabs()) diff --git a/examples/table/ansi.mojo b/examples/table/ansi.mojo index bbcc251..3580038 100644 --- a/examples/table/ansi.mojo +++ b/examples/table/ansi.mojo @@ -11,7 +11,7 @@ import mog fn main() raises: - var s = Style.new().foreground(mog.Color("240")) + var s = mog.new_style().foreground(mog.Color("240")) var t = new_table() t.width = 50 diff --git a/mog/style.mojo b/mog/style.mojo index e5969dd..4e113db 100644 --- a/mog/style.mojo +++ b/mog/style.mojo @@ -455,7 +455,7 @@ struct Style: Example: var: String = "..." - var user_style = Style.new().inline(True) + var user_style = mog.new_style().inline(True) print(user_style.render(user_input)) Args: @@ -655,7 +655,7 @@ struct Style: Example: var: String = "..." - var user_style = Style.new().max_width(16) + var user_style = mog.new_style().max_width(16) print(user_style.render(user_input)) Args: diff --git a/tests/integration/test_mog.mojo b/tests/integration/test_mog.mojo index 1e68ba0..310f207 100644 --- a/tests/integration/test_mog.mojo +++ b/tests/integration/test_mog.mojo @@ -16,7 +16,7 @@ from time import now fn dummy_style_func(row: Int, col: Int) -> Style: - var style = Style.new().horizontal_alignment(position.center).vertical_alignment(position.center).padding(0, 1) + var style = mog.new_style().horizontal_alignment(position.center).vertical_alignment(position.center).padding(0, 1) if row == 0: style = style.foreground(mog.Color("#c9a0dc")) return style @@ -29,7 +29,7 @@ fn dummy_style_func(row: Int, col: Int) -> Style: fn test_table() raises: var test = MojoTest("Testing table creation with and without headers") - var border_style = Style.new().foreground(mog.Color("#39E506")) + var border_style = mog.new_style().foreground(mog.Color("#39E506")) var table = Table( style_function=default_styles, @@ -72,7 +72,7 @@ fn test_table() raises: fn test_horizontal_joined_paragraphs() raises: var test = MojoTest("Testing Style rendering") var style_build_start = now() - var style = Style.new().bold().width(50).padding(1, 1, 1, 1).horizontal_alignment(position.center).border( + var style = mog.new_style().bold().width(50).padding(1, 1, 1, 1).horizontal_alignment(position.center).border( rounded_border() ).foreground(mog.Color("#c9a0dc")).border_foreground(mog.Color("#39E506")) var style_build_duration = now() - style_build_start @@ -130,7 +130,7 @@ fn test_horizontal_joined_paragraphs() raises: fn test_borderless_paragraph() raises: - var borderless_style = Style.new().width(50).padding(1, 2).horizontal_alignment(position.center).border( + var borderless_style = mog.new_style().width(50).padding(1, 2).horizontal_alignment(position.center).border( hidden_border() ).background(mog.Color("#c9a0dc"))