Це відео не доступне.
Перепрошуємо.
Unreasonably Easy Console Apps in Rust
Вставка
- Опубліковано 18 сер 2024
- Previous Episodes: • Multiuser Chat (4at)
Chapters:
- 0:00:00 - Announcement
- 0:00:42 - Intro
- 0:01:05 - Demo
- 0:04:04 - Crossterm
- 0:04:50 - Hello, World
- 0:06:12 - Adding Crossterm Dependency
- 0:07:16 - Docs
- 0:13:51 - MoveTo
- 0:21:15 - Clear
- 0:22:54 - Size of the Terminal
- 0:26:45 - Printing Text
- 0:30:56 - Event Loop
- 0:35:32 - Resize Event
- 0:36:48 - Planning out the App
- 0:38:07 - Efficient Rendering
- 0:39:39 - React devs like my videos
- 0:40:17 - Dash line
- 0:50:17 - Immediate Mode
- 0:51:53 - Rust devs joking
- 0:52:55 - Box-drawing chars
- 0:55:02 - Handling Input
- 0:57:48 - Raw Mode
- 0:59:27 - Ctrl+C
- 1:02:11 - Chat
- 1:04:59 - Reseting the Terminal
- 1:06:49 - Limit Chat Vertically
- 1:21:06 - Limit Chat Horizontally
- 1:24:53 - Limit Prompt Horizontally
- 1:26:48 - Pasting
- 1:28:36 - Plugin into the Network
- 1:38:22 - Testing locally
- 1:39:44 - Properly handling closed read end
- 1:40:39 - Setup tutorial
- 1:41:06 - Continue testing locally
- 1:43:13 - Committing
- 1:44:06 - Deploying
- 1:45:14 - Unhardcoding IP
- 1:48:50 - Cleaning up prompt on Esc
- 1:50:59 - Redeploying
- 1:52:10 - Testing with Viewers
- 1:53:55 - Outro
References:
- Crossterm - github.com/cro...
- Tsoding - 4at - github.com/tso...
Support:
- BTC: bc1qj820dmeazpeq5pjn89mlh9lhws7ghs9v34x9v9
- Servers: zap-hosting.co...
59:26 the vim beginner experience
lol
fun fact: crossterm supports all UNIX and Windows terminals down to Windows 7
Windows without VT , amazing.
features: crossterm supports all UNIX and Windows terminals down to Windows 7
And as a matter of fact, crossterm supports all UNIX and Windows terminals down to Windows 7
ncurses is actually newer than the web - it's from 1993 and Tim starts the web in 1991
But it's called ncurses because it's the *new* curses. The curses library was invented to improve Rogue, over a decade earlier, so curses does pre-date the web and even most GUIs
I always thought it meant new cursings, compared to the old cursings.
Because that's what you say when you have to use such libraries.
@@monad_tcp ah old difficult cursing... like, "damn your lineage and let the fields run barren wherever you rest your head" as opposed to new more efficient cursing, "fuck you".
i love how i am learning stuff in a better way by just watching your videos instead of tutorials
Building stuff yourself is even better.
@@ivanjermakov My hands and mind stop working when I have to think about it lol
@@maximus1172 it is just fear of making trash, you have to be humble and accept that anything you'll make at the beginninng will in fact be trash and then just iterate it till you have something that resembles a working program
@@javierflores09Not always. I can do all kind of trash but my mind is white noise 90% of time.
@@iamdozerq sleep better, intake tea with teaspoon of sugar, do not eat while thinking (makes you brain go into yum-yum-mode), eat before.
The goal you mentioned at the start of the video (reserve the last line of the terminal for input and have conversations go on above it), reminds me when I was in high school and wanted to make my own terminal chat application. I also didn't want to use any library, and more importantly, was too lazy to learn ncurses. So I did it the non-portable hacky way as one would.
Whenever a new message was received, I would just print "\b" `our_length` amount of times, where `our_length` is the length of the message our user is currently typing. Then print " " (space) `our_length` amount of times (\b doesn't remove the characters, it just makes ur cursor go back, so u need to write over them with a whitespace character). Now again print \b `our_length` amount of times to go back to the start of the line. Now print the received message, and then in the next line, print the user's currently typed-out message.
This gave the illusion that the user has a dedicated text field.
I learned about `cargo tree` today. Love the paranoia-oriented programming approach, helps keep react andys from `npm install` onto 800+ deps for a hello world project at bay
That's partly due to node's godawful community though. When you're developing a library, you need to be extra aware of any dependencies you pull in. For small things which are only like 1 or 2 functions, it's often a better idea to just recreate that functionality yourself rather than include an otherwise unnecessary extra dependency. When writing something which isn't intended to be consumed as a dependency itself there's less need to be quite so paranoid about things.
@@Bobbias A decent model might be to have two ways of adding a library, either as a "dependency" or just copy-pasting it into your source tree. You could imagine something like "npm copy" to just stick the files right in your src/ so you can use them or modify them as if they were your own source code.
@@Bobbiasthe literally can't do that, imagine duplicating code that already exists elsewhere in the world. Imagine writing your own code.
Totally "invented here" syndrome. Which is the opposite of not-invented-here in which you never use something you didn't make yourself. (which to be fair greatly simplifies and speeds up things, cut extremely the need for using outside libraries to a minimum)
@@Jack-sy6dithere's also the problem that JS is stupid and doesn't have a proper STL
Your killing my productivity... That's how awesome you are 🎉
Didn’t even realize that cargo doc would build local docs for deps, that’s incredibly useful
you also have the option to skip them with "--no-deps" I believe. Sometimes even docs take a while if you have a massive dependency tree and you just cargo cleaned lol
I speak french and it cannot do that 11:43
Best I can think of is «eaux», «noyaux» or «accueil»
You had become my first source of knowledge in programming and ... entertainment! Thank you really Tsoding
Thanks for the great videos! You inspired me to start a project I've been thinking about for a while and to use crossterm instead of a GUI.
I recently boosted the sensitivity of my mousewheel, hearing yours each time you scroll reminded me. It is so nice to just go one notch and a bunch of lines now.
Downloaded this video and watched it on a flight can’t complain
In my humble opinion crossterm is here to stay. Lots of big crates/projects use it. In the worse case a fork will be made like for tui-rs (aka ratatui now) and the transition was seamless !
> In my humble opinion crossterm is here to stay.
lol
What? Is it dead already? 😜
@@TsodingDaily Hehe don't quote me later but i use crossterm since 2019/2020 so i don't see it go away anytime soon.
Why do people feel this need for validation.
Does the library do what you need ?
Do any other libraries have a feature the one you are using doesn't have, no, then I fail to see the problem. If they have then you swap the libraries, or implement the feature in the library you're using , this is open source, baby.
And you literally have the source to fix shit later if it's needed.
Why must people only use what's popular. I don't get it, what a stupid metric. If something works, it works, this is engineering, not fashion.
@@monad_tcp Is this message addressed to me ?
this channel is simply gold
bump
Very informative video! I finally know how to flush, and how to clean
I am starting to like this guy. I hate anyone coding. But your commentary also just is amazing
you hate programmers?
@@slicerabbit6166
Ye. Dw, I hate myself first. My opinions anyways shouldn't matter.
why do you hate anyone wut @@hariranormal5584
this is what coding is meant to be like. just having fun learning a library. none of this learn what a hook is, why we dont want class components,, call back vs async. I dont want a new paradigm of coding, i just want to show something on the screen.
The hybrid Gopher/Ferris mascot is one of the most cursed programming-related things I've seen
i like to use `anyhow::Result` in my projects cos it's shorter to use `?` than `unwrap` and it's basically `Box` but instead of `Box` they use `Own` or something
and provide helper functions like `context` and `bail!`
Specifically, `Box` puts the vtable pointer in the box struct itself, turning it into a wide pointer; by contrast, `anyhow` puts the vtable pointer on the heap next to the thing that's boxed. This is slower, since it requires two dependent indirection where the first approach allows for parallel access (which with CPU pipelining is faster), but you don't really care if accessing your error is marginally slower usually and it means that if your non-error type in result is
You certainly don’t need a crate for handling errors and be able to use the ? operator.. All you need is a generic error struct and just implement From for MyError and you can use question mark operator everywhere.
@@yaksher Ideally your system shouldn't be throwing errors often enough for a performance impact like that to matter. I realize that's not always possible though, so of course there will be times where that may actually matter. But in general, that shouldn't be something you should worry about until the problem actually happens.
@@BobbiasThat was... exactly the point I made, yes.
@@yaksher People on the internet love to think that some practically irrelevant difference in performance somehow actually matters in their code, and nowhere did you say "this performance difference is meaningless".
I just wanted to make that crystal clear to the sizable portion of Tsoding's audience who are not experienced programmers and who have that tendency to be terrified of anything that remotely sounds like it might hurt performance without actually understanding things.
terminal raw mode?
It is good practice to safe the original states of the terminal settings that you change and restore them on exit (guaranteed by something like an exit or defer mechanism).
That is the first and last thing you should always do. Well, besides that little ctrl-c problem, hehehe
Would you think of making a rust tutorial series to teach people rust?
As of 39:13, I don't know if you will explain more on the terminal flickering or not. But i tried build a terminal animation but a lot more simpler, and it was because of your previous video about bouncing ball on the terminal. I think the flickering can be solved by rendering it really fast like 60 frame per second
It's amazing when terminals can stream text at tens of megabytes per second.
@@monad_tcp can they&
"Oh it even can handle mouse events. I am intrigued!"
Me: On the console? HERETIC!!!
Hehehe, thanks for the video, Tsoder!:)
Maybe a weird question I guess but in your recent AMA, your answer to the question “how to learn programming” was to just fuck around. I personally struggle with getting an idea for a project and having the motivation for it. If someone makes me write some program or code, I will do research and do the best I can but I just struggle with getting an idea for a person project. What would you (or anyone) recommend?
I think he's encouraging people to follow their curiosity. That said, you might not feel any particular inspiration or passion for making projects, and that can be OK too. Have you tried making tutorials to teach others? Or, have you tried taking any courses? Some people learn better with structure, accountability, and clear goals, versus exploratory/self-directed learning.
i was inspired to have a simple personal project because of a movie, i watch some things that may inspire me to create something, you could try it this way.
Would you mind telling me how i should feel about the rust programming language? I need something topical and snappy. Please I'm trying to base my whole personality off of this programming tool. Dude please
This communiity seems divided.. you'll end up having a bipolar personality lol
11:24 ~ 11:50 was hilarious
Actually not having a client and make everything work over something simple as netcat can be beneficial. The only problem is that server must do all the work of setting up terminal for you. Otherwise you can do netcat with rlwrap, but this limits you to one-line input, or do pipes in folders like ii does for IRC, where you can just cat file 'out' and write to other pipe 'in'.
This is a very good knowledge for RUST developers! Spasibo
i'm missing C videos
i'm missing Haskell videos
You really deserve more subs dude, a lot more
GUI is also very easy in rust with something like egui & egui_inspect (fork, because egui_inspect is kinda dead). I've been meaning to try clap and ratatui for cli and tui, but not sure there's that much point (for me, since adding egui_inspect to my structs is trivial enough, except for maybe headless access).
i can attest as someone who isnt that good at making actual guis that ratatui and clap/argh are very nice and easy to work with
egui_inspect is a fork of egui? egui is dead? what are you on about?
egui_inspect is a crate with derive macros for egui itself
egui is alive and well, last commit 6h ago
@@barbiefan3874 egui_inspect is dead, egui is of course fine and there are other inspect crates that are probably alive
@@barbiefan3874 I mean I use a fork of egui_inspect
@@barbiefan3874 I dont think that is what they said. They said they use egui and a fork of egui_inspect "because egui_inspect is kinda dead"
It seems that the import section is growing noticeably faster than the program code itself. :D
😅 you make it a fun journey... thankyou
At about 13:59ish minutes in you got annoyed about the compiler telling you you had unused imports and to remove them, but it then required you to put it back. The reason you initially had the unused import warning was because of your unwrap being in the wrong place, and therefore it was never actually requiring that type to be in scope, until you moved unwap to the correct line. I am no fan of Rust, but to be fair that isn't something that the compiler would have known to account for.
That it warns of unused imports is something it can handle. It just shouldn't do that.
Except it is, why do you need to import things you don't use directly, aka transitive dependencies. Just do Hindley&Milter type inference on that. I'm kidding, that would make compile times almost infinite .
Unless Rust is full of extension namespaces .
Then it really is fair
Thank you for way how you do stuff. I learned a lot about workflow.
Btw how you edit multiple lines in vim when adding second binary?
Why did raw mode fix the issue?
Malding over skill issues, classic zozing
I like his folder size at the bottom of the terminal 😎😈😎
"Can your French do that?" - Tsoding
youtube compression really dislikes scrolling
English: «Queueable»
Luxembourgish: hold my beer... «Zweeeeëg»!
Dutch: «koeieuier»
Funny this video just popped up as im switching from nodejs to rust. Coincidentally I learned about CLI just before switching. Will be fun.
Do you use lsp in emacs?
I have a question, why is it so hard to center an element in rust? ^^
Hi, currently addicted to Rust because of your rust videos...
Hey i wanna know what code editor you use for gui of c++
watching you manually type out all of the use items is driving me insane
i have gotten too used to autocomplete. it's eroding my brain
I still find it easier to just write a bash script with escape sequences
tats was awesome
Good stuff. Thanks a lot!
Sir!
Can you please explain Rust Lifetimes concept from ground
React bros don't even know that Windows was written before React.
26:31 yes, but only if you use Canvas
Actually the “{x:.
"-" * 30
@@gishee18 yes and that too
Rust's use of a sensible format syntax is much nicer to work with. C's format syntax is awful, even disregarding how broken printf et. al. are.
@@BobbiasC would be awful if it had a format capability.
printf is just a 0-day enabler.
Shots fired.
It seems the more often I see Rust, the more I dislike it ...
Your loss, I guess. The benefits are well worth pushing past that early prejudice based on an emotional reaction to the syntax (assuming that's all it is).
@@peter9477 You may be right. But I doubt it really is a loss ....
Another tsoding vod to get to sleep.
thank you x 3
i wonder if this terminal library can put a character in the lower right corner of the terminal without causing it to scroll to a new line. thats like the ultimate challenge for terminal libraries
I was working along with this video to make my own terminal app and unfortunately the answer seems to be no for windows
29:37 smooth :)
"Queue can fail"
Wait... if it can fail... shouldn't the rust compiler just have... rejected the code altogether? I thought you weren't allowed to ignore fail cases in Rust... at least not without unrwapping or something...
28:47 😵💫😵💫 i am supposed to be developing web right now.
.
.
.
.
..
Я так яростно закивал about that idiomatic shit, что ёжнулся головой о полку.
This guy is prime on crack!
@1:01:30 Named loops + breaks crying in the distance.
@1:10:10 Range indexing, crying in the distance. Why would you just index from where you need instead of iterating the entire thing every time. That would be insane.
@1:18:20 Sees it asking for parenthesis, immediately gives up instead of just putting the parenthesis where it said to (granted, the thing he ended up with is better, but still)
Yeah, that iterator being consumed from index 0 was cringe. 😂 Maybe the quit flag is OK, because you don't know what your cleanup needs, long-term.
@@ElPikacupacabra I mean, in Rust:
- you very rarely need cleanup because it's almost always done through destructors
- you can just... put the cleanup after the loop? Like you would anyway?
... does INCLUDE a call to if needed.
Just because you guys otherwise hate superfluous keystrokes (Emacs-User, hehe) like the devil, don't you?:) :P
But I get it. You do this because of your "IDE" and the headless duck programming style (error -> correct, error -> correct, error -> correct, and so on, hehehe)
(secret-pro-200-iq-monster-tip-hint: rust-analyzer in the IDE/Emacs ... )
Felca Programador :)
the jokes are on point with this one
yay
Is that Neovim?
it is emacs
At minute 10 it is sort of strange to see you making "fun" of the term queue and telling that the authors didn't know the term batch.
Are you deadly sure one preceeds and fully includes the another?
This is Rust program.. so be patient. lol nice.
You can now add the -Zthreads=8 environment flag on the nigthly build to use the specified number of threads during frontend compilation which should make it faster.
I cannot accept that you are not using autocomplete in Rust.
54:47 It's an Ukrainian flag? What is it doing there?
India💔
:)
is rust still the future or was it ruined because all the drama in the community ..?
Have you even tried programming in it or do you treat as just a fashion item?
Rust is a tool, imagine saying I will not use a hammer because I don’t like the hammer making company
@@vinos1629 i mean, well, in some contexts this argument may apply. what if the said company makes shitty hammers? 😅
@@vinos1629 I say that. But then again, I work in hardware design, we love politics in our industry. The company I work for, arm, has a policy to only use tools from the people who aren't total dipsticks and is very anti open source. Not saying rust is that, rust is baby compared to drama in our industry.
@@nyyakko you can argue rust is shitty, but for me it’s a useful tool in a lot of applications, If they make it shit I will stop using jt
You keep repeating yourself, I've noticed that it comes more often when you are out of the script. It denotes that your body is making use of Alternate Current for tasks that asks for Continuous Current. It is a backup so your system won't stall, but renders a choppier experience, undermining all your apparent strengths. Perfection comes primarily from brushing off imperfections. But it doesn't mean that the signal at the end will be better. In our case, perfection is when everything functions as expected, without extra loops.
41:39 lol I've been rereading the perl book, and one of their fundamental operators, alongside `+` and `*`, is `x`, the "string multiplication" operator, so literally `stdout.write("-" x w)` would do what you need here. I still don't know if perl is a good language but it's definitely a fun language
that's so cursed
In python you can also do `"-" * w`
How is string multiplication defined as an operation?
@@benisroodOperator overloading? Heck, you might even be able to define a trait in Rust that lets you do the same.
Perl is quite powerful for string manipulations, but a real pain to read. It leads people to write very cryptic code.
legacy-go-version
I don't get why urmom wasn't queued but still waited for the clear and move with no flush
やっぱrustってクソっすね、忌憚の無い意見ってやつっす