Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yad
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vladislav
yad
Commits
a889ad42
Commit
a889ad42
authored
Jun 30, 2019
by
Victor Ananjevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add --formatted option to text dialog
parent
fe110808
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
40 deletions
+41
-40
option.c
src/option.c
+3
-0
text.c
src/text.c
+37
-40
yad.h
src/yad.h
+1
-0
No files found.
src/option.c
View file @
a889ad42
...
...
@@ -607,6 +607,8 @@ static GOptionEntry text_options[] = {
N_
(
"Make URI clickable"
),
NULL
},
{
"uri-color"
,
0
,
0
,
G_OPTION_ARG_STRING
,
&
options
.
text_data
.
uri_color
,
N_
(
"Use specified color for links"
),
N_
(
"COLOR"
)
},
{
"formatted"
,
0
,
0
,
G_OPTION_ARG_NONE
,
&
options
.
text_data
.
formatted
,
N_
(
"Use pango markup"
),
NULL
},
{
NULL
}
};
...
...
@@ -1674,6 +1676,7 @@ yad_options_init (void)
options
.
text_data
.
margins
=
0
;
options
.
text_data
.
hide_cursor
=
TRUE
;
options
.
text_data
.
uri_color
=
"blue"
;
options
.
text_data
.
formatted
=
FALSE
;
#ifdef HAVE_SOURCEVIEW
/* Initialize sourceview data */
...
...
src/text.c
View file @
a889ad42
...
...
@@ -317,11 +317,19 @@ handle_stdin (GIOChannel * channel, GIOCondition condition, gpointer data)
{
gchar
*
utftext
=
g_convert_with_fallback
(
string
->
str
,
string
->
len
,
"UTF-8"
,
"ISO-8859-1"
,
NULL
,
NULL
,
NULL
,
NULL
);
gtk_text_buffer_insert
(
GTK_TEXT_BUFFER
(
text_buffer
),
&
end
,
utftext
,
-
1
);
if
(
options
.
text_data
.
formatted
&&
!
options
.
common_data
.
editable
)
gtk_text_buffer_insert_markup
(
GTK_TEXT_BUFFER
(
text_buffer
),
&
end
,
utftext
,
-
1
);
else
gtk_text_buffer_insert
(
GTK_TEXT_BUFFER
(
text_buffer
),
&
end
,
utftext
,
-
1
);
g_free
(
utftext
);
}
else
gtk_text_buffer_insert
(
GTK_TEXT_BUFFER
(
text_buffer
),
&
end
,
string
->
str
,
string
->
len
);
{
if
(
options
.
text_data
.
formatted
&&
!
options
.
common_data
.
editable
)
gtk_text_buffer_insert_markup
(
GTK_TEXT_BUFFER
(
text_buffer
),
&
end
,
string
->
str
,
string
->
len
);
else
gtk_text_buffer_insert
(
GTK_TEXT_BUFFER
(
text_buffer
),
&
end
,
string
->
str
,
string
->
len
);
}
if
(
options
.
common_data
.
tail
)
{
...
...
@@ -354,52 +362,41 @@ fill_buffer_from_file ()
#ifdef HAVE_SOURCEVIEW
GtkSourceLanguage
*
lang
;
#endif
FILE
*
f
;
g
char
buf
[
2048
]
;
gint
remaining
=
0
;
gchar
*
bu
f
;
g
size
len
;
GError
*
err
=
NULL
;
if
(
options
.
common_data
.
uri
==
NULL
)
return
;
f
=
fopen
(
options
.
common_data
.
uri
,
"r"
);
if
(
f
==
NULL
)
{
g_printerr
(
_
(
"Cannot open file '%s': %s
\n
"
),
options
.
common_data
.
uri
,
g_strerror
(
errno
));
return
;
}
gtk_text_buffer_get_iter_at_offset
(
GTK_TEXT_BUFFER
(
text_buffer
),
&
iter
,
0
);
while
(
!
feof
(
f
))
{
gint
count
;
const
char
*
leftover
;
int
to_read
=
2047
-
remaining
;
count
=
fread
(
buf
+
remaining
,
1
,
to_read
,
f
);
buf
[
count
+
remaining
]
=
'\0'
;
g_utf8_validate
(
buf
,
count
+
remaining
,
&
leftover
);
g_assert
(
g_utf8_validate
(
buf
,
leftover
-
buf
,
NULL
));
gtk_text_buffer_insert
(
GTK_TEXT_BUFFER
(
text_buffer
),
&
iter
,
buf
,
leftover
-
buf
);
remaining
=
(
buf
+
remaining
+
count
)
-
leftover
;
memmove
(
buf
,
leftover
,
remaining
);
if
(
remaining
>
6
||
count
<
to_read
)
break
;
}
if
(
remaining
)
if
(
!
g_file_get_contents
(
options
.
common_data
.
uri
,
&
buf
,
&
len
,
&
err
))
{
g_printerr
(
_
(
"
Invalid UTF-8 data encountered reading file %s
\n
"
),
options
.
common_data
.
uri
);
g_printerr
(
_
(
"
Cannot open file '%s': %s
\n
"
),
options
.
common_data
.
uri
,
err
->
message
);
return
;
}
/* We had a newline in the buffer to begin with. (The buffer always contains
* a newline, so we delete to the end of the buffer to clean up.
gtk_text_buffer_get_iter_at_offset
(
GTK_TEXT_BUFFER
(
text_buffer
),
&
iter
,
0
);
if
(
!
g_utf8_validate
(
buf
,
-
1
,
NULL
))
{
gchar
*
utftext
=
g_convert_with_fallback
(
buf
,
-
1
,
"UTF-8"
,
"ISO-8859-1"
,
NULL
,
NULL
,
NULL
,
NULL
);
if
(
options
.
text_data
.
formatted
&&
!
options
.
common_data
.
editable
)
gtk_text_buffer_insert_markup
(
GTK_TEXT_BUFFER
(
text_buffer
),
&
end
,
utftext
,
-
1
);
else
gtk_text_buffer_insert
(
GTK_TEXT_BUFFER
(
text_buffer
),
&
end
,
utftext
,
-
1
);
g_free
(
utftext
);
}
else
{
if
(
options
.
text_data
.
formatted
&&
!
options
.
common_data
.
editable
)
gtk_text_buffer_insert_markup
(
GTK_TEXT_BUFFER
(
text_buffer
),
&
end
,
buf
,
-
1
);
else
gtk_text_buffer_insert
(
GTK_TEXT_BUFFER
(
text_buffer
),
&
end
,
buf
,
-
1
);
}
/* We had a newline in the buffer to begin with. (The buffer always contains
* a newline, so we delete to the end of the buffer to clean up.
*/
gtk_text_buffer_get_end_iter
(
GTK_TEXT_BUFFER
(
text_buffer
),
&
end
);
...
...
src/yad.h
View file @
a889ad42
...
...
@@ -423,6 +423,7 @@ typedef struct {
gboolean
uri
;
gboolean
hide_cursor
;
gchar
*
uri_color
;
gboolean
formatted
;
}
YadTextData
;
#ifdef HAVE_SOURCEVIEW
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment