Browse Source

The second version we refactored together with Olari

master
Robert Reimann 3 years ago
parent
commit
da1c412091
  1. 49
      main.go

49
main.go

@ -1,54 +1,23 @@
package main package main
import ( import (
"fmt"
"io/ioutil"
"os" "os"
"strings" "strings"
) )
func main() { func main() {
// If we have any other number of parameters, than one
if len(os.Args[1:]) != 1 {
return
}
// Separate every line
lines := strings.Split(string(os.Args[1]), "\\n") lines := strings.Split(string(os.Args[1]), "\\n")
// The most stupid fix in the world, for the empty lines for ; lines[len(lines)-1] == ""; lines = lines[:len(lines)-1] {
// This variable stores how many new lines we add to the very end defer os.Stdout.WriteString("\n")
newLineCount := 0
// Just remove the new lines from the very end... splitting at \n causes empty strings to occur in the slice
for lines[len(lines)-1] == "" {
lines = lines[:len(lines)-1]
newLineCount++
}
// Read in the alphabet
alphabet, err := ioutil.ReadFile("standard.txt")
if err != nil {
return
} }
alpha := strings.Split(string(alphabet), "\n") bytes, _ := os.ReadFile("standard.txt")
alphabet := strings.Split(string(bytes), "\n")
// Loop through the slice of lines for _, line := range lines {
for _, v := range lines { for i := 1; i < 9; i++ {
// Loop through the lines of the font for _, char := range line {
// All the characters are made up of eight lines os.Stdout.WriteString(alphabet[(char-32)*9+rune(i)])
// Essentially, 'i' tells us which line of printing we are at
for i := 0; i < 8; i++ {
// Loop through the current line
for _, w := range v {
// Get the index of the character in the font file
fmt.Print(alpha[(w-32)*9+rune(i+1)])
} }
// Print out a new line for the future parts of the characters os.Stdout.WriteString("\n")
fmt.Println()
} }
} }
// Add the newLines to the very end of the printing
for ; newLineCount > 0; newLineCount-- {
fmt.Println()
}
} }

Loading…
Cancel
Save