Skip to content

Refactor shell starter templates and solutions #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions compiled_starters/go/cmd/myshell/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ func main() {
// You can use print statements as follows for debugging, they'll be visible when running tests.
fmt.Println("Logs from your program will appear here!")

reader := bufio.NewReader(os.Stdin)
for {
// Uncomment this block to pass the first stage
// fmt.Fprint(os.Stdout, "$ ")
_, _ = reader.ReadString('\n')
}
// Uncomment this block to pass the first stage
// fmt.Fprint(os.Stdout, "$ ")

// Wait for user input
bufio.NewReader(os.Stdin).ReadString('\n')
}
11 changes: 6 additions & 5 deletions compiled_starters/python/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ def main():
# You can use print statements as follows for debugging, they'll be visible when running tests.
print("Logs from your program will appear here!")

while True:
# Uncomment this block to pass the first stage
# sys.stdout.write("$ ")
# sys.stdout.flush()
input()
# Uncomment this block to pass the first stage
# sys.stdout.write("$ ")
# sys.stdout.flush()

# Wait for user input
input()


if __name__ == "__main__":
Expand Down
15 changes: 8 additions & 7 deletions compiled_starters/rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#[allow(unused_imports)]
use std::io::{self, Write};

fn main() {
// You can use print statements as follows for debugging, they'll be visible when running tests.
println!("Logs from your program will appear here!");

// Uncomment this block to pass the first stage
// let stdin = io::stdin();
// loop {
// print!("$ ");
// io::stdout().flush().unwrap();
// let mut input = String::new();
// stdin.read_line(&mut input).unwrap();
// }
// print!("$ ");
// io::stdout().flush().unwrap();

// Wait for user input
let stdin = io::stdin();
let mut input = String::new();
stdin.read_line(&mut input).unwrap();
}
9 changes: 4 additions & 5 deletions solutions/go/01-oo8/code/cmd/myshell/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
)

func main() {
reader := bufio.NewReader(os.Stdin)
for {
fmt.Fprint(os.Stdout, "$ ")
_, _ = reader.ReadString('\n')
}
fmt.Fprint(os.Stdout, "$ ")

// Wait for user input
bufio.NewReader(os.Stdin).ReadString('\n')
}
15 changes: 7 additions & 8 deletions solutions/go/01-oo8/diff/cmd/myshell/main.go.diff
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@@ -1,19 +1,15 @@
@@ -1,18 +1,14 @@
package main

import (
Expand All @@ -11,11 +11,10 @@
- // You can use print statements as follows for debugging, they'll be visible when running tests.
- fmt.Println("Logs from your program will appear here!")
-
reader := bufio.NewReader(os.Stdin)
for {
- // Uncomment this block to pass the first stage
- // fmt.Fprint(os.Stdout, "$ ")
+ fmt.Fprint(os.Stdout, "$ ")
_, _ = reader.ReadString('\n')
}
- // Uncomment this block to pass the first stage
- // fmt.Fprint(os.Stdout, "$ ")
+ fmt.Fprint(os.Stdout, "$ ")

// Wait for user input
bufio.NewReader(os.Stdin).ReadString('\n')
}
9 changes: 5 additions & 4 deletions solutions/python/01-oo8/code/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@


def main():
while True:
sys.stdout.write("$ ")
sys.stdout.flush()
input()
sys.stdout.write("$ ")
sys.stdout.flush()

# Wait for user input
input()


if __name__ == "__main__":
Expand Down
17 changes: 9 additions & 8 deletions solutions/python/01-oo8/diff/app/main.py.diff
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
@@ -1,16 +1,12 @@
@@ -1,17 +1,13 @@
import sys


def main():
- # You can use print statements as follows for debugging, they'll be visible when running tests.
- print("Logs from your program will appear here!")
-
while True:
- # Uncomment this block to pass the first stage
- # sys.stdout.write("$ ")
- # sys.stdout.flush()
+ sys.stdout.write("$ ")
+ sys.stdout.flush()
input()
- # Uncomment this block to pass the first stage
- # sys.stdout.write("$ ")
- # sys.stdout.flush()
+ sys.stdout.write("$ ")
+ sys.stdout.flush()

# Wait for user input
input()


if __name__ == "__main__":
Expand Down
13 changes: 7 additions & 6 deletions solutions/rust/01-oo8/code/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#[allow(unused_imports)]
use std::io::{self, Write};

fn main() {
print!("$ ");
io::stdout().flush().unwrap();

// Wait for user input
let stdin = io::stdin();
loop {
print!("$ ");
io::stdout().flush().unwrap();
let mut input = String::new();
stdin.read_line(&mut input).unwrap();
}
let mut input = String::new();
stdin.read_line(&mut input).unwrap();
}
26 changes: 11 additions & 15 deletions solutions/rust/01-oo8/diff/src/main.rs.diff
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
@@ -1,15 +1,11 @@
@@ -1,16 +1,12 @@
#[allow(unused_imports)]
use std::io::{self, Write};

fn main() {
- // You can use print statements as follows for debugging, they'll be visible when running tests.
- println!("Logs from your program will appear here!");
-
- // Uncomment this block to pass the first stage
- // let stdin = io::stdin();
- // loop {
- // print!("$ ");
- // io::stdout().flush().unwrap();
- // let mut input = String::new();
- // stdin.read_line(&mut input).unwrap();
- // }
+ let stdin = io::stdin();
+ loop {
+ print!("$ ");
+ io::stdout().flush().unwrap();
+ let mut input = String::new();
+ stdin.read_line(&mut input).unwrap();
+ }
- // print!("$ ");
- // io::stdout().flush().unwrap();
+ print!("$ ");
+ io::stdout().flush().unwrap();

// Wait for user input
let stdin = io::stdin();
let mut input = String::new();
stdin.read_line(&mut input).unwrap();
}
9 changes: 2 additions & 7 deletions solutions/rust/01-oo8/explanation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ Study and uncomment the relevant code:

```rust
// Uncomment this block to pass the first stage
let stdin = io::stdin();
loop {
print!("$ ");
io::stdout().flush().unwrap();
let mut input = String::new();
stdin.read_line(&mut input).unwrap();
}
print!("$ ");
io::stdout().flush().unwrap();
```

Push your changes to pass the first stage:
Expand Down
11 changes: 5 additions & 6 deletions starter_templates/go/cmd/myshell/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ func main() {
// You can use print statements as follows for debugging, they'll be visible when running tests.
fmt.Println("Logs from your program will appear here!")

reader := bufio.NewReader(os.Stdin)
for {
// Uncomment this block to pass the first stage
// fmt.Fprint(os.Stdout, "$ ")
_, _ = reader.ReadString('\n')
}
// Uncomment this block to pass the first stage
// fmt.Fprint(os.Stdout, "$ ")

// Wait for user input
bufio.NewReader(os.Stdin).ReadString('\n')
}
11 changes: 6 additions & 5 deletions starter_templates/python/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ def main():
# You can use print statements as follows for debugging, they'll be visible when running tests.
print("Logs from your program will appear here!")

while True:
# Uncomment this block to pass the first stage
# sys.stdout.write("$ ")
# sys.stdout.flush()
input()
# Uncomment this block to pass the first stage
# sys.stdout.write("$ ")
# sys.stdout.flush()

# Wait for user input
input()


if __name__ == "__main__":
Expand Down
15 changes: 8 additions & 7 deletions starter_templates/rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#[allow(unused_imports)]
use std::io::{self, Write};

fn main() {
// You can use print statements as follows for debugging, they'll be visible when running tests.
println!("Logs from your program will appear here!");

// Uncomment this block to pass the first stage
// let stdin = io::stdin();
// loop {
// print!("$ ");
// io::stdout().flush().unwrap();
// let mut input = String::new();
// stdin.read_line(&mut input).unwrap();
// }
// print!("$ ");
// io::stdout().flush().unwrap();

// Wait for user input
let stdin = io::stdin();
let mut input = String::new();
stdin.read_line(&mut input).unwrap();
}
Loading