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

sile-typesetter / sile / 9304049654

30 May 2024 02:12PM UTC coverage: 60.021% (-14.7%) from 74.707%
9304049654

push

github

web-flow
Merge 1a26b4f22 into a1fd105f8

6743 of 12900 new or added lines in 186 files covered. (52.27%)

347 existing lines in 49 files now uncovered.

10311 of 17179 relevant lines covered (60.02%)

3307.34 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 ()
×
NEW
18
   if not outfile then
×
NEW
19
      local fname = self:getOutputFilename()
×
NEW
20
      outfile = fname == "-" and io.stdout or io.open(fname, "w+")
×
21
   end
22
end
23

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

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

37
function outputter:finish ()
×
NEW
38
   self:_ensureInit()
×
NEW
39
   self:runHooks("prefinish")
×
NEW
40
   outfile:close()
×
41
end
42

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

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

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

NEW
87
function outputter:drawRaw (literal)
×
NEW
88
   self:_ensureInit()
×
NEW
89
   outfile:write(literal)
×
90
end
91

92
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

© 2026 Coveralls, Inc