• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 6713089468

31 Oct 2023 10:19PM UTC coverage: 74.636% (+12.4%) from 62.266%
6713089468

push

github

alerque
fix(backends): Fix plain text backend to work in LuaJIT/Lua 5.1

1 of 1 new or added line in 1 file covered. (100.0%)

11800 of 15810 relevant lines covered (74.64%)

6984.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/outputters/text.lua
1
local base = require("outputters.base")
×
2

3
local cursorX = 0
×
4
local cursorY = 0
×
5

6
local outfile
7
local started = false
×
8

9
local outputter = pl.class(base)
×
10
outputter._name = "text"
×
11
outputter.extension = "txt"
×
12

13
-- The outputter init can't actually initialize output (as logical as it might
14
-- have seemed) because that requires a page size which we don't know yet.
15
-- function outputter:_init () end
16

17
function outputter:_ensureInit ()
×
18
  if not outfile then
×
19
    local fname = self:getOutputFilename()
×
20
    outfile = fname == "-" and io.stdout or io.open(fname, "w+")
×
21
  end
22
end
23

24
function outputter:_writeline (...)
×
25
  self:_ensureInit()
×
26
  local args = table.pack(...)
×
27
  for i=1, #args do
×
28
    outfile:write(args[i])
×
29
  end
30
end
31

32
function outputter:newPage ()
×
33
  self:_ensureInit()
×
34
  outfile:write(" ")
×
35
end
36

37
function outputter:finish ()
×
38
  self:_ensureInit()
×
39
  outfile:close()
×
40
end
41

42
function outputter.getCursor (_)
×
43
  return cursorX, cursorY
×
44
end
45

46
function outputter:setCursor (x, y, relative)
×
47
  self:_ensureInit()
×
48
  local bs = SILE.measurement("0.8bs"):tonumber()
×
49
  local spc = SILE.measurement("0.8spc"):tonumber()
×
50
  local offset = relative and { x = cursorX, y = cursorY } or { x = 0, y = 0 }
×
51
  local newx, newy = offset.x + x, offset.y - y
×
52
  if started then
×
53
    if newx < cursorX then
×
54
        outfile:write("\n")
×
55
    elseif newy > cursorY then
×
56
      if newy - cursorY > bs then
×
57
        outfile:write("\n")
×
58
      else
59
        outfile:write("‫")
×
60
      end
61
    elseif newx > cursorX then
×
62
      if newx:tonumber() - cursorX:tonumber() > spc then
×
63
        outfile:write(" ")
×
64
      else
65
        outfile:write("‫")
×
66
      end
67
    end
68
  end
69
  cursorY = newy
×
70
  cursorX = newx
×
71
end
72

73
function outputter:drawHbox (value, width)
×
74
  self:_ensureInit()
×
75
  width = SU.cast("number", width)
×
76
  if not value.text then return end
×
77
  self:_writeline(value.text)
×
78
  if width > 0 then
×
79
    started = true
×
80
    cursorX = cursorX + width
×
81
  end
82
end
83

84
return outputter
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc