Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "bufio"
- "fmt"
- "os"
- "strings"
- )
- func main() {
- args := ""
- if len(os.Args) == 3 {
- args = string(os.Args[2])
- args = args + ".txt"
- } else if len(os.Args) == 2 {
- args = "font.txt"
- } else {
- fmt.Println("Program uses os.Args as input. To run the program from terminal do it like this: \n\nExample: go run . 'string you want to print' font")
- }
- if _, err := os.Stat(args); os.IsNotExist(err) {
- fmt.Println("Program uses os.Args as input. To run the program from terminal do it like that: \n\nExample: go run . 'string you want to print' font")
- os.Exit(0)
- }
- font, _ := readLines(args)
- text := os.Args[1]
- textLines := strings.Split(text, "\\n")
- writeText(textLines, font)
- }
- // This function prints the lines
- func writeText(textLines []string, font []string) {
- for i := 0; i < len(textLines); i++ {
- x := 0
- for j := 0; j < 8; j++ {
- for k := 0; k < len(textLines[i]); k++ {
- // Find the right line for the letter
- pos := 1 + (int(textLines[i][k])-32)*9 + x
- fmt.Printf(font[pos])
- }
- x++
- fmt.Println()
- }
- }
- }
- // This function reads the font file
- func readLines(path string) ([]string, error) {
- file, err := os.Open(path)
- if err != nil {
- return nil, err
- }
- defer file.Close()
- var lines []string
- scanner := bufio.NewScanner(file)
- for scanner.Scan() {
- lines = append(lines, scanner.Text())
- }
- return lines, scanner.Err()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement