Skip to content

Commit

Permalink
Remove unneeded _format_unencoded_with_lineno function from IRCFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayowel committed Nov 1, 2022
1 parent 8371114 commit 1e2a56e
Showing 1 changed file with 11 additions and 30 deletions.
41 changes: 11 additions & 30 deletions pygments/formatters/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,52 +128,33 @@ def __init__(self, **options):
self._lineno = 0

def _write_lineno(self, outfile):
self._lineno += 1
outfile.write("\n%04d: " % self._lineno)
if self.linenos:
self._lineno += 1
outfile.write("%04d: " % self._lineno)

def _format_unencoded_with_lineno(self, tokensource, outfile):
def format_unencoded(self, tokensource, outfile):
self._write_lineno(outfile)

for ttype, value in tokensource:
if value.endswith("\n"):
self._write_lineno(outfile)
value = value[:-1]
color = self.colorscheme.get(ttype)
while color is None:
ttype = ttype.parent
ttype = ttype[:-1]
color = self.colorscheme.get(ttype)
if color:
color = color[self.darkbg]
spl = value.split('\n')
for line in spl[:-1]:
self._write_lineno(outfile)
if line:
outfile.write(ircformat(color, line[:-1]))
outfile.write(ircformat(color, line))
outfile.write('\n')
self._write_lineno(outfile)
if spl[-1]:
outfile.write(ircformat(color, spl[-1]))
else:
outfile.write(value)

outfile.write("\n")

def format_unencoded(self, tokensource, outfile):
if self.linenos:
self._format_unencoded_with_lineno(tokensource, outfile)
return

for ttype, value in tokensource:
color = self.colorscheme.get(ttype)
while color is None:
ttype = ttype[:-1]
color = self.colorscheme.get(ttype)
if color:
color = color[self.darkbg]
spl = value.split('\n')
for line in spl[:-1]:
if line:
outfile.write(ircformat(color, line))
outfile.write(line)
outfile.write('\n')
self._write_lineno(outfile)
if spl[-1]:
outfile.write(ircformat(color, spl[-1]))
else:
outfile.write(value)
outfile.write(spl[-1])

0 comments on commit 1e2a56e

Please sign in to comment.