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

sile-typesetter / sile / 12313034533

13 Dec 2024 09:28AM UTC coverage: 60.234% (-0.7%) from 60.941%
12313034533

push

github

web-flow
Merge 5a7694dff into d737b2656

9 of 25 new or added lines in 5 files covered. (36.0%)

145 existing lines in 16 files now uncovered.

12801 of 21252 relevant lines covered (60.23%)

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

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

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

NEW
38
function outputter.abort ()
×
NEW
39
   if started then
×
NEW
40
      outfile:close()
×
NEW
41
      started = false
×
42
   end
43
end
44
function outputter:finish ()
×
45
   self:_ensureInit()
×
46
   self:runHooks("prefinish")
×
47
   outfile:close()
×
NEW
48
   started = false
×
49
end
50

51
function outputter.getCursor (_)
×
52
   return cursorX, cursorY
×
53
end
54

55
function outputter:setCursor (x, y, relative)
×
56
   self:_ensureInit()
×
57
   local bs = SILE.types.measurement("0.8bs"):tonumber()
×
58
   local spc = SILE.types.measurement("0.8spc"):tonumber()
×
59
   local offset = relative and { x = cursorX, y = cursorY } or { x = 0, y = 0 }
×
60
   local newx, newy = offset.x + x, offset.y - y
×
61
   if started then
×
62
      if newx < cursorX then
×
63
         outfile:write("\n")
×
64
      elseif newy > cursorY then
×
65
         if newy - cursorY > bs then
×
66
            outfile:write("\n")
×
67
         else
68
            outfile:write("\u{202b}")
×
69
         end
70
      elseif newx > cursorX then
×
71
         if newx:tonumber() - cursorX:tonumber() > spc then
×
72
            outfile:write(" ")
×
73
         else
74
            outfile:write("\u{202b}")
×
75
         end
76
      end
77
   end
78
   cursorY = newy
×
79
   cursorX = newx
×
80
end
81

82
function outputter:drawHbox (value, width)
×
83
   self:_ensureInit()
×
84
   width = SU.cast("number", width)
×
85
   if not value.text then
×
86
      return
×
87
   end
88
   self:_writeline(value.text)
×
89
   if width > 0 then
×
90
      cursorX = cursorX + width
×
91
   end
92
end
93

94
function outputter:drawRaw (literal)
×
95
   self:_ensureInit()
×
96
   outfile:write(literal)
×
97
end
98

99
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