Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
af154ce8
Commit
af154ce8
authored
19 years ago
by
deuce
Browse files
Options
Downloads
Patches
Plain Diff
Add a function to make a set of lines from a string.
parent
a532a534
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
exec/fseditor.js
+153
-2
153 additions, 2 deletions
exec/fseditor.js
with
153 additions
and
2 deletions
exec/fseditor.js
+
153
−
2
View file @
af154ce8
...
@@ -184,6 +184,7 @@ function set_cursor()
...
@@ -184,6 +184,7 @@ function set_cursor()
if
(
xpos
>
80
)
if
(
xpos
>
80
)
xpos
=
80
;
xpos
=
80
;
console
.
gotoxy
(
x
,
y
);
console
.
gotoxy
(
x
,
y
);
console
.
attributes
=
curattr
;
}
}
var
lastinsert
=
false
;
var
lastinsert
=
false
;
...
@@ -686,7 +687,157 @@ function redraw_screen()
...
@@ -686,7 +687,157 @@ function redraw_screen()
}
}
/*
/*
* Converts the current lines to a single string and returns and array.
* Converts a pair of strings to an array of lines.
*
* str: The text of the message.
* attr: An attribute string of the message
* nl_is_hardcr: Indicates that every NL is a hard cr
*/
function
make_lines
(
str
,
attr
,
nl_is_hardcr
)
{
nl
=
new
Array
();
var
oldstr
=
str
;
var
oldattr
=
attr
;
thisattr
=
7
;
/* Fix up the attr string to match str in length...
* strip/interpret ^A and strip CRs
*/
str
=
''
;
attr
=
''
;
while
(
oldstr
.
length
)
{
if
(
oldattr
.
length
)
{
thisattr
=
ascii
(
oldattr
.
substr
(
0
,
1
));
oldattr
=
oldattr
.
substr
(
1
);
}
switch
(
oldstr
.
substr
(
0
,
1
))
{
case
'
\r
'
:
oldstr
=
oldstr
.
substr
(
1
);
break
;
case
'
\
x01
'
:
oldstr
=
oldstr
.
substr
(
1
);
switch
(
oldstr
.
substr
(
0
,
1
))
{
case
'
K
'
:
thisattr
&=
0xf8
;
break
;
case
'
R
'
:
thisattr
=
(
thisattr
&
0xf8
)
|
RED
;
break
;
case
'
G
'
:
thisattr
=
(
thisattr
&
0xf8
)
|
GREEN
;
break
;
case
'
Y
'
:
thisattr
=
(
thisattr
&
0xf8
)
|
BROWN
;
break
;
case
'
B
'
:
thisattr
=
(
thisattr
&
0xf8
)
|
BLUE
;
break
;
case
'
M
'
:
thisattr
=
(
thisattr
&
0xf8
)
|
MAGENTA
;
break
;
case
'
C
'
:
thisattr
=
(
thisattr
&
0xf8
)
|
CYAN
;
break
;
case
'
W
'
:
thisattr
=
(
thisattr
&
0xf8
)
|
LIGHTGRAY
;
break
;
case
'
0
'
:
thisattr
=
(
thisattr
&
0x8f
);
break
;
case
'
1
'
:
thisattr
=
(
thisattr
&
0x8f
)
|
(
RED
<<
4
);
break
;
case
'
2
'
:
thisattr
=
(
thisattr
&
0x8f
)
|
(
GREEN
<<
4
);
break
;
case
'
3
'
:
thisattr
=
(
thisattr
&
0x8f
)
|
(
BROWN
<<
4
);
break
;
case
'
4
'
:
thisattr
=
(
thisattr
&
0x8f
)
|
(
BLUE
<<
4
);
break
;
case
'
5
'
:
thisattr
=
(
thisattr
&
0x8f
)
|
(
MAGENTA
<<
4
);
break
;
case
'
6
'
:
thisattr
=
(
thisattr
&
0x8f
)
|
(
CYAN
<<
4
);
break
;
case
'
7
'
:
thisattr
=
(
thisattr
&
0x8f
)
|
(
LIGHTGRAY
<<
4
);
break
;
case
'
H
'
:
thisattr
|=
0x08
;
break
;
case
'
I
'
:
thisattr
|=
0x80
;
break
;
case
'
N
'
:
thisattr
=
7
;
break
;
case
'
\
x01
'
:
str
=
str
+
'
\
x01
'
;
attr
=
attr
+
ascii
(
thisattr
);
break
;
default
:
}
oldstr
=
oldstr
.
substr
(
1
);
break
;
default
:
str
=
str
+
oldstr
.
substr
(
0
,
1
);
oldstr
=
oldstr
.
substr
(
1
);
attr
=
attr
+
ascii
(
thisattr
);
}
}
while
(
str
.
length
>
0
)
{
var
m
=
str
.
match
(
/^
(
.
{0,79}
*
)(\n?)
/
);
if
(
m
!=
null
)
{
/* We have zero or more characters followed by zero or more spaces followed by zero or one \n */
nl
[
nl
.
length
]
=
new
Line
;
nl
[
nl
.
length
-
1
].
text
=
m
[
1
]
+
m
[
2
];
nl
[
nl
.
length
-
1
].
attr
=
attr
.
substr
(
0
,
nl
[
nl
.
length
-
1
].
text
.
length
);
str
=
str
.
substr
(
m
[
0
].
length
);
attr
=
attr
.
substr
(
m
[
0
].
length
);
if
(
nl_is_hardcr
)
{
if
(
m
[
3
].
length
>
0
)
nl
[
nl
.
length
-
1
].
hardcr
=
true
;
}
else
{
/* Deduce if this is a hard or soft CR as follows */
/* If the next char is a nl, or whitespace, it is hard. */
/* If there is room for the first word of the next line on this
* line, it is hard */
/* Otherwise, it is soft. */
/* Next line starts with whitespace - is hard */
if
(
str
.
search
(
/^
\s
/
)
!=-
1
)
nl
[
nl
.
length
-
1
].
hardcr
=
true
;
else
{
/* Get first word of next line */
var
m2
=
str
.
match
(
/^
(
.*
\s)
/
);
if
(
m2
!=
null
)
{
if
(
m
[
1
].
length
+
m2
[
1
].
length
<
80
)
nl
[
nl
.
length
-
1
].
hardcr
=
true
;
}
}
}
/* If we have 79 chars in a row with no spaces and not a whitspace
* on the end, and the forst char of the next line isn't whitespace,
* we have a kludged line */
if
(
nl
[
nl
.
length
-
1
].
text
.
length
==
79
&&
nl
[
nl
.
length
-
1
].
text
.
search
(
/
\s
/
)
==-
1
&&
str
.
search
(
/^
\s
/
)
==-
1
)
nl
[
nl
.
length
-
1
].
kludged
=
true
;
}
else
{
/* Not sure how THIS could happen */
alert
(
"
The impossible happened.
"
);
console
.
pause
();
exit
();
}
}
return
(
nl
);
}
/*
* Converts the current lines to a single string and returns an array.
* the array contains two strings... the first string is the text string and the
* the array contains two strings... the first string is the text string and the
* second string is the attribute string. If embed_colour is true, the second
* second string is the attribute string. If embed_colour is true, the second
* string is blank.
* string is blank.
...
@@ -782,7 +933,7 @@ function make_strings(soft,embed_colour)
...
@@ -782,7 +933,7 @@ function make_strings(soft,embed_colour)
attrs
+=
line
[
i
].
attr
;
attrs
+=
line
[
i
].
attr
;
}
}
if
(
soft
||
line
[
i
].
hardcr
)
{
if
(
soft
||
line
[
i
].
hardcr
)
{
/* Trim whitespace */
/* Trim whitespace
from end
*/
str
=
str
.
replace
(
/
(\s
*
)
$/
,
function
(
str
,
spaces
,
offset
,
s
)
{
str
=
str
.
replace
(
/
(\s
*
)
$/
,
function
(
str
,
spaces
,
offset
,
s
)
{
if
(
!
embed_colour
)
{
if
(
!
embed_colour
)
{
/* Remove attributes for trimmed spaces */
/* Remove attributes for trimmed spaces */
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment