You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
// Lexington is a command line tool to convert between several formats used for screenwriting.
|
|
// When you write a screenplay in Fountain, you can use this tool to convert it into other formats.
|
|
// The tool uses an internal format called lex which can be used to tweak the output.
|
|
// Run the compiled tool with --help to get information about usage.
|
|
package main
|
|
|
|
import (
|
|
"git.kiefte.eu/lapingvino/printdraftfast/pdf"
|
|
"git.kiefte.eu/lapingvino/printdraftfast/rules"
|
|
|
|
"flag"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
start := time.Now()
|
|
defer func() {
|
|
log.Printf("Conversion took %v", time.Since(start))
|
|
}()
|
|
config := flag.String("config", "printdraftfast.toml", "Configuration file to use.")
|
|
dump := flag.Bool("dumpconfig", false, "Dump the default configuration to the location of --config to be adapted manually.")
|
|
elements := flag.String("e", "default", "Element settings from settings file to use.")
|
|
input := flag.String("i", "-", "Input from provided filename. - means standard input.")
|
|
output := flag.String("o", "-", "Output to provided filename.")
|
|
help := flag.Bool("help", false, "Show this help message")
|
|
flag.Parse()
|
|
|
|
if *help {
|
|
flag.PrintDefaults()
|
|
return
|
|
}
|
|
|
|
if *dump {
|
|
err := rules.Dump(*config)
|
|
if err != nil {
|
|
log.Println("Error dumping configuration: ", err)
|
|
}
|
|
log.Println("Configuration dumped to ", *config)
|
|
return
|
|
}
|
|
|
|
var infile io.Reader
|
|
var outfile io.Writer
|
|
|
|
conf := rules.GetConf(*config)
|
|
|
|
if *input == "-" {
|
|
infile = os.Stdin
|
|
log.Println("Reading from Stdin")
|
|
} else {
|
|
var err error
|
|
infile, err = os.Open(*input)
|
|
if err != nil {
|
|
log.Println("Error opening file: ", err)
|
|
return
|
|
}
|
|
}
|
|
|
|
// TODO: Parser goes here
|
|
|
|
if *output == "-" && len(ins) > 0 && ins[0] != "" {
|
|
*output = ins[0] + ".pdf"
|
|
}
|
|
if *output == "-" {
|
|
log.Println("Cannot write PDF to standard output")
|
|
return
|
|
}
|
|
pdf.Create(*output, conf.Elements[*elements], i)
|
|
}
|