lib/livetext/userapi.rb in livetext-0.9.25 vs lib/livetext/userapi.rb in livetext-0.9.26
- old
+ new
@@ -1,31 +1,43 @@
-require_relative 'formatline'
+# require_relative 'formatline' # FIXME meh, because of #format
+require_relative 'lineparser' # FIXME meh, because of #format
# Encapsulate the UserAPI as a class
class Livetext::UserAPI
+ KBD = File.new("/dev/tty", "r")
+ TTY = File.new("/dev/tty", "w")
+
+ DotSpace = ". " # Livetext::Sigil + Livetext::Space
+
attr_accessor :data, :args
def initialize(live)
@live = live
@vars = live.vars
end
+ def api
+ @live.api
+ end
+
+ def dot
+ @live
+ end
+
def setvar(var, val)
- # FIXME don't like this...
- str, sym = var.to_s, var.to_sym
- Livetext::Vars[str] = val
- Livetext::Vars[sym] = val
+ Livetext::Vars[var] = val # Now indifferent and "safe"
end
def check_existence(file, msg)
STDERR.puts msg unless File.exist?(file)
end
def data=(value)
+# TTY.puts "in #{__FILE__}: api = #{@live.api.inspect}"
@data = value
@args = format(@data).chomp.split
end
def args
@@ -43,13 +55,11 @@
@line = @live.nextline if peek =~ /^ *$/
return true # This way, dot commands will usually return true
end
def comment?(str)
- sigil = Livetext::Sigil
- c1 = sigil + Livetext::Space
- str.index(c1) == 0
+ str.index(DotSpace) == 0
end
def trailing?(char)
return true if ["\n", " ", nil].include?(char)
return false
@@ -108,12 +118,11 @@
str
end
def format(line)
return "" if line == "\n" || line.nil?
- line2 = Livetext::FormatLine.parse!(line)
-# line.replace(line2)
+ line2 = Livetext::LineParser.parse!(line)
line2
end
def passthru(line)
return if @live.nopass
@@ -129,9 +138,17 @@
@live.body << "\n" unless str.end_with?("\n")
end
def out!(str = "")
@live.body << str # no newline
+ end
+
+ def tty(*args)
+ TTY.puts *args
+ end
+
+ def err(*args)
+ STDERR.puts *args
end
def puts(*args)
@live.output.puts *args
end