Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
somebody1234 committed Apr 6, 2018
1 parent a3a22a3 commit 0320e97
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 44 deletions.
68 changes: 26 additions & 42 deletions charcoal.py
Expand Up @@ -472,9 +472,9 @@ def __setitem__(self, i, value):
start = i.start or 0
stop = len(self) if i.stop is None else i.stop
for i in range(start, stop):
self.charcoal.PutAt(self[i], self.xs[i], self.ys[i])
self.charcoal.Put(self[i], self.xs[i], self.ys[i])
return
self.charcoal.PutAt(self[i], self.xs[i], self.ys[i])
self.charcoal.Put(self[i], self.xs[i], self.ys[i])

def __getitem__(self, i):
if isinstance(i, slice):
Expand Down Expand Up @@ -805,62 +805,44 @@ def Get(self):

def HasCharAt(self, x, y):
"""
Get() -> str
HasCharAt() -> bool
Returns value of cell under cursor.
Returns whether there is a cell under the cursor
"""
x0, y0, self.x, self.y = self.x, self.y, x, y
y_index = self.y - self.top
y_index = y - self.top
result = True
if (
y_index < len(self.lines) and
y_index >= 0 and
self.x - self.indices[y_index] < self.lengths[y_index] and
self.x - self.indices[y_index] >= 0
x - self.indices[y_index] < self.lengths[y_index] and
x - self.indices[y_index] >= 0
):
result = (
self.lines[y_index][self.x - self.indices[y_index]] != "\000"
self.lines[y_index][x - self.indices[y_index]] != "\000"
)
self.x, self.y = x0, y0
return result

def PutAt(self, string, x, y):
def Put(self, string, x=None, y=None):
"""
PutAt(string, x, y)
Put(string, x=None, y=None)
Put string at position x, y.
"""
initial_x = self.x
initial_y = self.y
self.x = x
self.y = y
self.Put(string)
self.x = initial_x
self.y = initial_y
Put string at position x, y. Defaults to cursor position.
def Put(self, string):
"""
Put()
Put string at cursor position.
"""
y_index = self.y - self.top
line = self.lines[y_index]
delta_index = len(re.match("^\000*", line).group())
self.indices[y_index] += delta_index
x = self.x if x is None else x
y = self.y if y is None else y
y_index = y - self.top
x_index = self.indices[y_index]
line = re.sub("\000+$", "", line[delta_index:])
line = self.lines[y_index]
if not line:
length = len(string)
self.lines[y_index] = string
self.indices[y_index] = self.x
self.indices[y_index] = x
self.lengths[y_index] = length
self.right_indices[y_index] = self.x + length
self.right_indices[y_index] = x + length
return
start = self.x - x_index
start = x - x_index
end = start + len(string)
if start - len(line) > 0 or end < 0:
self.background_inside = True
Expand All @@ -871,10 +853,12 @@ def Put(self, string):
"\000" * -end +
line[max(0, end):]
)
if "\000" in self.lines[y_index]:
self.background_inside = True
if start - len(line) > 0 or -end > 0:
self.background_inside = True
if self.x < x_index:
self.indices[y_index] = self.x
if x < x_index:
self.indices[y_index] = x
length = len(self.lines[y_index])
self.lengths[y_index] = length
self.right_indices[y_index] = self.indices[y_index] + length
Expand Down Expand Up @@ -1017,7 +1001,7 @@ def PrintLine(
):
if (
self.y < self.top or self.y > (self.top + len(self.lines))
) and re.match("\000*$", string):
) and not string:
continue
self.FillLines()
final = (string * (length // len(string) + 1))[:length]
Expand All @@ -1040,7 +1024,7 @@ def PrintLine(
coordinates.Add(self.x, self.y)
self.FillLines()
current = self.Get()
if overwrite or not current or current == "\x00":
if overwrite or not current or current == "\000":
self.Put(character)
self.Move(direction)
if not move_at_end:
Expand Down Expand Up @@ -3383,7 +3367,7 @@ def Extend(self, horizontal=0, vertical=0):
horizontal, vertical = int(horizontal) + 1, int(vertical) + 1
if horizontal:
self.background_inside = True
joiner = "\x00" * (horizontal - 1)
joiner = "\000" * (horizontal - 1)
self.lines = [joiner.join(line) for line in self.lines]
self.lengths = [
(length - 1) * horizontal + 1 for length in self.lengths
Expand Down Expand Up @@ -3483,7 +3467,7 @@ def PeekAll(self):
for i in range(len(self.lines)):
line, x = self.lines[i], self.indices[i]
for character in line:
if character == "\x00":
if character == "\000":
x += 1
continue
result += [character]
Expand Down
1 change: 1 addition & 0 deletions charcoaltoken.py
Expand Up @@ -34,6 +34,7 @@
"Dictionary",

"Program",
"NonEmptyProgram",
"Body",
"Command",

Expand Down
4 changes: 4 additions & 0 deletions interpreterprocessor.py
Expand Up @@ -674,6 +674,10 @@ def direction(dir):
lambda r: lambda c: ((r[0](c) or True) and r[2](c)),
lambda r: lambda c: None
],
CT.NonEmptyProgram: [
lambda r: lambda c: ((r[0](c) or True) and r[2](c)),
lambda r: lambda c: r[0](c)
],
CT.Body: [
lambda r: lambda c: r[1](c),
lambda r: lambda c: r[1](c),
Expand Down
3 changes: 2 additions & 1 deletion stringifierprocessor.py
Expand Up @@ -99,8 +99,8 @@ def number(s):
lambda r: r[0],
lambda r: [("l", "")] + r[0],
lambda r: [("m", ""), ("<", "⟦")] + r[1] + [(">", "⟧")] + r[3],
lambda r: [("d", "")] + r[0] + r[1],
lambda r: [("f", ""), ("<", "«")] + r[1] + [(">", "»")] + r[3],
lambda r: [("d", "")] + r[0] + r[1],
lambda r: r[0] + r[1],
lambda r: r[0][:1] + r[2] + r[3] + r[4] + r[5] + r[0][1:],
lambda r: r[0][:1] + r[2] + r[3] + r[4] + r[5] + r[0][1:],
Expand Down Expand Up @@ -173,6 +173,7 @@ def number(s):
] + [lambda r: [("o", "▷" )] + r[2] + [("!", "e")]] * 2,

CT.Program: [lambda r: r[0] + r[1], lambda r: []],
CT.NonEmptyProgram: [lambda r: r[0] + r[1], lambda r: r[0]],
CT.Body: [
lambda r: [("<", "«")] + r[1] + [(">", "»")],
lambda r: r[0],
Expand Down
1 change: 1 addition & 0 deletions unicodegrammars.py
Expand Up @@ -164,6 +164,7 @@
],

CT.Program: [[CT.Command, CT.S, CT.Program], []],
CT.NonEmptyProgram: [[CT.Command, CT.S, CT.Program], [CT.Command]],
CT.Body: [
["«", CT.Program, "»"],
["«", CT.Program, CT.EOF],
Expand Down
3 changes: 2 additions & 1 deletion verbosegrammars.py
Expand Up @@ -91,8 +91,8 @@
[CT.Name, CT.S],
[CT.List, CT.S],
["[", CT.Multidirectional, "]", CT.S],
[CT.Dictionary, CT.S],
["{", CT.Program, "}", CT.S],
[CT.Dictionary, CT.S],

This comment has been minimized.

Copy link
@urkerab

urkerab Nov 21, 2019

Collaborator

Unfortunately this change broke empty dictionaries. Would it make sense to require the program to be non-empty?

This comment has been minimized.

Copy link
@somebody1234

somebody1234 Dec 30, 2019

Author Collaborator

apologies for the late reply... but example please? i feel like not programming for a while has made me dumber lol

This comment has been minimized.

Copy link
@somebody1234

somebody1234 Jan 2, 2020

Author Collaborator

i hope it's fixed now ._. wow never knew charcoal is still so insanely broken

This comment has been minimized.

Copy link
@urkerab

urkerab Dec 27, 2020

Collaborator

Yeah, seems fixed on master, thanks!

[CT.OtherOperator, CT.S],
[
CT.LazyQuarternary, CT.LP, CT.Expression, CT.Expression,
Expand Down Expand Up @@ -205,6 +205,7 @@
["evalvar", CT.LP, CT.Expression, CT.RP]
],
CT.Program: [[CT.Command, CT.Program], []],
CT.NonEmptyProgram: [[CT.Command, CT.Program], [CT.Command]],
CT.Body: [["{", CT.Program, "}"], [CT.Command]],
CT.Command: [
["InputString", CT.LP, CT.Name, CT.RP, CT.S],
Expand Down

0 comments on commit 0320e97

Please sign in to comment.