My Text editor program in Rust programming language managed to get input characters from screen terminal as created a file once program ends.
Read the code here
https://github.com/davnav/RustEditor/blob/master/main.rs
If I started writing this in C, i would have end up in "Segmentation fault". But even though Rust compiler makes you learn the syntax and new concepts ( mutation,scope,borrow etc) . But once we managed to compile the code, the program produces the output as we expected.(won't go to the buffer overflows or pointer problems)
Terminal is not pointing to left most position when I hit enter, looks like I need to handle this manually.
I have not build any 'struct' for 'Editor' or 'Rows'. Not sure much syntax for 'struct' in Rust. Reading more this now.
I think I can move to the 'text viewer' pages in the below documentation.
https://viewsourcecode.org/snaptoken/kilo/04.aTextViewer.html
Tuesday, July 17, 2018
Monday, July 9, 2018
Finally refreshed the terminal screen
It was always a big question in me that all schooling/engineering programming courses( C or assembly) teach Fibonacci series or some tough logic program ( something like for a given number 'N' search the subset bla bla .. ) . But when I looked at the computer , I wondered how they build these screens/commands and applications.. is it with Maths ? is it with Fibonacci series /prime numbers? (They are not, it made up of simple logics.. but its like a 'building blocks' game)
My expectation from computer classes was to build some screens or applications , ( but generally I got bored with theory . there was my fault too , i admit ) . Computer applications/commands did not look like mathematical problem ,But computer subjects seems to me as mathematics subject. ( I know they really need maths, when we deep dive).
But as a beginner, I misunderstood that someone who knows deep maths can only do something with computer .. but actually that is not the case.
Whatever programs I studied/taught to do something with stdin ( standard input) or stdout( standard /the screen), are something like 'reverse string' or 'search character', but they did not generate any motivation to build some real world applications, rather I got scared even to attempt/read big programs, thinking it might require big logical algorithms that my brain can't digest. but as student I always wanted to build something like 'vi' (editor) or some commands or something having windows (not Microsoft windows) screen. At least I wanted to know how these functionalities are coming in the screen.
When I build some functionality that actual 'vi' editor has , I feels like I am writing programs as a professional (Really its not the case)
Having said all these story :-) as a hobby project , I am trying to build an editor based on the documentation https://viewsourcecode.org/snaptoken/kilo/03.rawInputAndOutput.html
I am learning lot of things when I wanted my program to do some functionality that 'vi' editor does.
More over I am trying to build this in Rust language which is a new generation computer programming language , capable of replacing 'C' language. Every system programmers should try to learn it as per http://web.stanford.edu/class/cs140e/
:-)
My text editor draft , just refreshed the screen :-)
https://github.com/davnav/RustEditor
The clear screen functionality can be easily built with below code, but it was never known to me ( as I know only Fibonacci ... :-) )
// Refresh the screen by writing "x1b[2J" byte to screen
io::stdout().write(b"\x1b[2J");
println!();
// align the cursor to the left top by writing "\x1b[H" byte to screen
io::stdout().write(b"\x1b[H");
but be aware , Rust compiler is ruthless :-) . it makes us read the documentation thoroughly.
My expectation from computer classes was to build some screens or applications , ( but generally I got bored with theory . there was my fault too , i admit ) . Computer applications/commands did not look like mathematical problem ,But computer subjects seems to me as mathematics subject. ( I know they really need maths, when we deep dive).
But as a beginner, I misunderstood that someone who knows deep maths can only do something with computer .. but actually that is not the case.
Whatever programs I studied/taught to do something with stdin ( standard input) or stdout( standard /the screen), are something like 'reverse string' or 'search character', but they did not generate any motivation to build some real world applications, rather I got scared even to attempt/read big programs, thinking it might require big logical algorithms that my brain can't digest. but as student I always wanted to build something like 'vi' (editor) or some commands or something having windows (not Microsoft windows) screen. At least I wanted to know how these functionalities are coming in the screen.
When I build some functionality that actual 'vi' editor has , I feels like I am writing programs as a professional (Really its not the case)
Having said all these story :-) as a hobby project , I am trying to build an editor based on the documentation https://viewsourcecode.org/snaptoken/kilo/03.rawInputAndOutput.html
I am learning lot of things when I wanted my program to do some functionality that 'vi' editor does.
More over I am trying to build this in Rust language which is a new generation computer programming language , capable of replacing 'C' language. Every system programmers should try to learn it as per http://web.stanford.edu/class/cs140e/
:-)
My text editor draft , just refreshed the screen :-)
https://github.com/davnav/RustEditor
The clear screen functionality can be easily built with below code, but it was never known to me ( as I know only Fibonacci ... :-) )
// Refresh the screen by writing "x1b[2J" byte to screen
io::stdout().write(b"\x1b[2J");
println!();
// align the cursor to the left top by writing "\x1b[H" byte to screen
io::stdout().write(b"\x1b[H");
but be aware , Rust compiler is ruthless :-) . it makes us read the documentation thoroughly.
Wednesday, July 4, 2018
do we need to take care 'String' type carefully ?
When I tried to do something with "Strings" in C programming language, either it won't give the desired result or I end up in 'Segmentation fault'. Lot of books in C show "Strings" manipulating with pointers. I like C in the sense that we can access the characters with the memory where they sit. But when I compile the full program, it compiles without any error , but finally when I run it , normally I endup in "Segmentation fault".
So thought of learning some string manipulation/Methods in Rust Programming language.
https://doc.rust-lang.org/std/string/struct.String.html#method.from
So thought of learning some string manipulation/Methods in Rust Programming language.
https://doc.rust-lang.org/std/string/struct.String.html#method.from