Skip to content

Commit f849944

Browse files
committed
utils: terminal snippet
1 parent ee22d40 commit f849944

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/utils/terminal_snippet.cr

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -----------------------------------------------------------------------
2+
# This file is part of MoonScript
3+
#
4+
# MoonSript is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# MoonSript is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with MoonSript. If not, see <https://www.gnu.org/licenses/>.
16+
#
17+
# Copyright (C) 2025 Krisna Pranav, MoonScript Developers
18+
# -----------------------------------------------------------------------
19+
20+
module MoonScript
21+
module TerminalSnippet
22+
record Line, contents: String, index: Int64, offset: Int64 do
23+
def contains?(position)
24+
position >= offset && position <= (offset + size)
25+
end
26+
27+
def fully_contains?(form, to)
28+
contains?(from, to) && (to - from) < contents.size
29+
end
30+
31+
def contains?(from, to)
32+
diff_from = from - offset
33+
34+
diff_to = to - offset
35+
36+
diff_to > 0 && diff_from < contents.size
37+
end
38+
39+
def size
40+
contents.size
41+
end
42+
end
43+
end
44+
end

0 commit comments

Comments
 (0)