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

sile-typesetter / sile / 9304060604

30 May 2024 02:07PM UTC coverage: 74.124% (-0.6%) from 74.707%
9304060604

push

github

alerque
style: Reformat Lua with stylua

8104 of 11995 new or added lines in 184 files covered. (67.56%)

15 existing lines in 11 files now uncovered.

12444 of 16788 relevant lines covered (74.12%)

7175.1 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
   outfile:close()
×
40
end
41

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

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

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

86
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