toasty
toasty
MModular
Created by toasty on 5/12/2024 in #community-showcase
Mog: Style definitions for nice terminal layouts (inspired by charmbracelet/lipgloss)
No description
4 replies
MModular
Created by Tyoma Makeev on 9/8/2024 in #questions
What's the thing with global variables?
They’ve said that it results in undefined behavior, so it’s not really supported at this time. Hopefully soon! You can define top level constants using alias though
6 replies
MModular
Created by Caroline on 9/5/2024 in #community-showcase
Modverse #42 is out!
@Caroline I’m here on discord too!
13 replies
MModular
Created by mad alex 1997 on 8/28/2024 in #community-showcase
NuMojo V0.2 Release: Simplified Type Handling, New Features, and Enhanced Compatibility
I've had some luck with rattler build and using prefix to host conda packages if you're interested, you're able to set up dependencies and have them installed along with your package via magic install. I created this channel to share later for whomever was interested. Waiting for Mojo 24.5 so things stabilize a little bit. https://prefix.dev/channels/mojo-community
5 replies
MModular
Created by toasty on 8/28/2024 in #questions
Usage of mojo test
Ah gotcha, thanks! I’ll give it a try with the mojopkg file, that’s usually how I test in automation but I didn’t get that far this time. Might just wait until mojo test is improved a bit though, mojo-pytest has been working well so far!
9 replies
MModular
Created by toasty on 8/14/2024 in #community-showcase
Reading from stdin
Just pulled in the latest version of nightly, I see the updates there!
17 replies
MModular
Created by toasty on 8/14/2024 in #community-showcase
Reading from stdin
Awesome, that’s great to hear!
17 replies
MModular
Created by toasty on 8/14/2024 in #community-showcase
Reading from stdin
I opened up a PR to add the stdin struct and input function, any help on fixing up the tests would be awesome! 😄 https://github.com/modularml/mojo/pull/3392
17 replies
MModular
Created by toasty on 8/14/2024 in #community-showcase
Reading from stdin
Any thoughts on where a struct like this should live? I defaulted to dropping it in sys like python, but would builtin.io be preferable?
17 replies
MModular
Created by toasty on 8/14/2024 in #community-showcase
Reading from stdin
Awesome, I'd appreciate that. I have some tests written, but couldn't run more than one at a time. I'll clean up my feature branch and submit a PR sometime soon 🙂
17 replies
MModular
Created by toasty on 8/14/2024 in #community-showcase
Reading from stdin
I developed this intending to open a PR into nightly, but got caught up with figuring out how to make the stdin input repeatable for tests. I may just open the PR and look for some guidance from the stdlib team and/or maintainers.
17 replies
MModular
Created by Dmitry Salin on 7/14/2024 in #community-showcase
io_uring
@Darkmatter I've seen you reference io_uring a few times, this might be of interest for you!
145 replies
MModular
Created by toasty on 5/12/2024 in #community-showcase
Mog: Style definitions for nice terminal layouts (inspired by charmbracelet/lipgloss)
Mog has been updated with my upstream changes in the mist, weave, and gojo packages! It is now ~90% faster (on my Mac M2)! The layout render is now taking ~15-16ms instead of ~140-150ms like I stated in the previous update. The changes to mist and weave minimized the number of string to int conversions that were taking place. And weave is making fewer copies of Strings now that I'm using bytes and string slices instead of copying bytes lists around. For gojo, I added a naive function to estimate how long a given character is. For example, emojis would often break the code, something like, 🔥, would have an actual cell length of 2. Same with east asian characters. These are now appropriately being counted as 2 characters, of course YMMV on different systems I have not tested. The Table struct has been cleaned up and a new more complex example has been added! Please check it out here: https://github.com/thatstoasty/mog/blob/main/demos/tapes/pokemon.gif https://github.com/thatstoasty/mog/blob/main/examples/table/pokemon.mojo I've also cleaned up many of the docstrings and examples for the structs/functions intended for the user. I decided to lean on usage of file scope variables for the examples a bit more, even though they break when you run mojo build and try running the compiled binary instead.
4 replies
MModular
Created by toasty on 6/11/2024 in #community-showcase
Mist and Weave: ANSI Styling and text formatting libraries
Made a fairly big change to how mist works. It no longer uses hex codes that are text eg #ffffff but instead it uses integers 0xffffff. This helped unify how ANSI and Hex color codes were being handled and lead to a pretty substantial improvement in the benchmarks! The text version is a bit nicer on the eyes, but not needing to handle variants and string conversions enabled mog styles to be defined as aliases and file scope vars. I was surprised to see the time it takes to render colored text drop by 90%. I ran a few thousand iterations on my Mac M2 and the mean dropped from roughly 0.035ms to 0.0035ms. I guess converting a String to an int then back again for the ansi sequence was eating up a lot of time. This change also lead to a 50% speedup for mog as well! I'm expecting that lib to be impacted by String operations much more, since it's splitting strings into lines and recombining it several times when it renders the content.
3 replies
MModular
Created by toasty on 6/11/2024 in #community-showcase
Mist and Weave: ANSI Styling and text formatting libraries
Just pushed a few QOL changes for mist. The TerminalStyle struct can now be an alias! It’s not much faster than just declaring it as a var, but the real win is that styles can now be a var or alias at the file scope after the refactor. To do this I had to remove any usage of str(), try, and dictionaries from the critical path of the code. If declaring it as an alias, a profile must given as an arg though. Querying the terminal for the colors it supports cannot happen at compile time.
3 replies
MModular
Created by toasty on 6/16/2024 in #community-showcase
Gojo: Experiments in porting over Golang stdlib into Mojo
Gojo has been updated to include some UDP socket structs! I've also included some examples for some basic tcp and udp server/clients and an example of using bufio.Scanner. https://github.com/thatstoasty/gojo/tree/main/examples Example UDP server using the listen_udp function
from gojo.net import UDPAddr, listen_udp, HostPort
import gojo.io


fn main() raises:
var listener = listen_udp("udp", UDPAddr("127.0.0.1", 12000))

while True:
var dest = List[UInt8](capacity=16)
var bytes_read: Int
var remote: HostPort
var err: Error
bytes_read, remote, err = listener.read_from(dest)
if err:
raise err

dest.append(0)
var message = String(dest^)
print("Message received:", message)
message = message.upper()
var bytes_sent: Int
bytes_sent, err = listener.write_to(message.as_bytes(), UDPAddr(remote.host, remote.port))
print("Message sent:", message)
from gojo.net import UDPAddr, listen_udp, HostPort
import gojo.io


fn main() raises:
var listener = listen_udp("udp", UDPAddr("127.0.0.1", 12000))

while True:
var dest = List[UInt8](capacity=16)
var bytes_read: Int
var remote: HostPort
var err: Error
bytes_read, remote, err = listener.read_from(dest)
if err:
raise err

dest.append(0)
var message = String(dest^)
print("Message received:", message)
message = message.upper()
var bytes_sent: Int
bytes_sent, err = listener.write_to(message.as_bytes(), UDPAddr(remote.host, remote.port))
print("Message sent:", message)
3 replies
MModular
Created by Jack Clayton on 5/11/2024 in #community-showcase
mojo-pytest: Mojo test runner and pytest plugin
I’ve been using mojo pytest to run tests on all my projects for months now! Great project 🙏🏾
11 replies
MModular
Created by toasty on 5/12/2024 in #community-showcase
Prism: CLI Library (inspired by Golang's Cobra)
Prism has been updated for Mojo 24.4! Due to changes with how Arc works, and with self references or lists of references being difficult/impossible. I had to modify the flow for a user a bit. For example
fn init() -> None:
var root_command = Arc(
Command(
name="my",
description="This is a dummy command!",
run=test,
)
)
root_command[].persistent_flags.add_bool_flag(name="required", shorthand="r", usage="Always required.")
root_command[].persistent_flags.add_string_flag(name="host", shorthand="h", usage="Host")
root_command[].persistent_flags.add_string_flag(name="port", shorthand="p", usage="Port")
root_command[].mark_persistent_flag_required("required")

var tool_command = Arc(Command(name="tool", description="This is a dummy command!", run=tool_func))
tool_command[].flags.add_bool_flag(name="also", shorthand="a", usage="Also always required.")
tool_command[].flags.add_string_flag(name="uri", shorthand="u", usage="URI")
root_command[].add_command(tool_command)

# Make sure to add the child command to the parent before marking flags.
# add_command() will merge persistent flags from the parent into the child's flags.
tool_command[].mark_flag_required("also")
tool_command[].mark_flags_required_together("host", "port")
tool_command[].mark_flags_mutually_exclusive("host", "uri")

root_command[].execute()
fn init() -> None:
var root_command = Arc(
Command(
name="my",
description="This is a dummy command!",
run=test,
)
)
root_command[].persistent_flags.add_bool_flag(name="required", shorthand="r", usage="Always required.")
root_command[].persistent_flags.add_string_flag(name="host", shorthand="h", usage="Host")
root_command[].persistent_flags.add_string_flag(name="port", shorthand="p", usage="Port")
root_command[].mark_persistent_flag_required("required")

var tool_command = Arc(Command(name="tool", description="This is a dummy command!", run=tool_func))
tool_command[].flags.add_bool_flag(name="also", shorthand="a", usage="Also always required.")
tool_command[].flags.add_string_flag(name="uri", shorthand="u", usage="URI")
root_command[].add_command(tool_command)

# Make sure to add the child command to the parent before marking flags.
# add_command() will merge persistent flags from the parent into the child's flags.
tool_command[].mark_flag_required("also")
tool_command[].mark_flags_required_together("host", "port")
tool_command[].mark_flags_mutually_exclusive("host", "uri")

root_command[].execute()
Commands must be turned into an Arc[Command] when initially created. This is so the relationship between commands can be preserved when you call add_command. Also, modifying a commands flagset through command methods has been removed. Users should alter a command's flags through the flags field(s) directly. Like so
root_command[].persistent_flags.add_bool_flag(name="required", shorthand="r", usage="Always required.")
tool_command[].flags.add_string_flag(name="uri", shorthand="u", usage="URI")
root_command[].persistent_flags.add_bool_flag(name="required", shorthand="r", usage="Always required.")
tool_command[].flags.add_string_flag(name="uri", shorthand="u", usage="URI")
6 replies
MModular
Created by toasty on 5/12/2024 in #community-showcase
Mog: Style definitions for nice terminal layouts (inspired by charmbracelet/lipgloss)
Mog has been updated for Mojo 24.4! I'll need to start including a changelog, but execution time has improved slightly by incorporating the new bytes buffer and string builder implementation from my other project, gojo. I added a new benchmarks directory for a few example benchmarks in rendering text with styling applied. Currently it just has a simple styling test, layout test (rendering the first image in the readme), and rendering a "large" text file (~4-5MB with 47k+ lines). You can run this on your machine with mojo run benchmarks/run.mojo. That will also format the benchmark reports into a table using the table module from mog! I'm quite happy with the performance so far! I'm seeing around ~140-150ms to render the layout image which fairly quick for all of the components it's rendering and joining together. For the future state, I'm really looking forward to improvements on the compile time front so we can start defining mog styles at comp time. Same with being able to define vars at the file level.
4 replies
MModular
Created by toasty on 6/2/2024 in #questions
What features or libraries are you waiting for before you start using Mojo in your domain?
Postgres is my preferred flavor of RDBMS as well! Would be great to have something there. I’ve tried my hand at wrapping the C API for DuckDB and but couldn’t figure out how to actually get query results 😂
11 replies