# ---- Regex Gadget UI ----
#' @inheritParams regex_gadget
regexplain_gadget_ui <- function(text = NULL, pattern = NULL, start_page = "Text") {
miniPage(
shiny::includeCSS(system.file("styles", "groups.css", package = "regexplain")),
shiny::includeCSS(system.file("styles", "gadget.css", package = "regexplain")),
gadgetTitleBar(
"RegExplain",
right = miniTitleBarButton("done", "Send RegEx To Console", TRUE)
),
miniTabstripPanel(
selected = match.arg(start_page, c("Text", "RegEx", "Output", "Help")),
# --- UI - Tab - Text ----
miniTabPanel(
"Text",
icon = icon("file-text-o"),
miniContentPanel(
fillCol(
textAreaInputAlt(
"text",
label = "Text to search or parse",
value = paste(text, collapse = "\n"),
resize = "both",
width = "100%",
height = "90%",
placeholder = "Paste, enter, or edit your sample text here."
)
)
)
),
# ---- UI - Tab - Regex ----
miniTabPanel(
"RegEx",
icon = icon("terminal"),
miniContentPanel(
tags$div(
id = "regexPage",
class = "container-fluid",
style = "height: 90%",
fluidRow(
id = "regexInput",
tags$div(
class = "col-12",
textInputCode(
"pattern",
HTML(
"RegEx",
format(
#
tags$button(
id = "regex-format-help",
type = "button",
class = "btn btn-sm btn-link",
style = "line-height: 1;padding: 0;font-size: inherit;",
`data-toggle` = "popover",
`data-trigger` = "hover",
`data-placement` = "bottom",
`data-content` = paste(
"
Enter your regular expressions in",
"standard RegExp format.
",
"In other words, use single slashes \\",
"rather than double slahes \\\\.
"
),
title = "Regular Expression Format",
shiny::icon("question-circle", "fa-sm")
)
)
),
width = "100%",
value = pattern,
placeholder = "Standard RegEx, e.g. \\w+_\\d{2,4}\\s+",
tags$span(
class = "input-group-btn",
id = "library_show_container",
actionButton("library_show", "Library", class = "btn-primary")
)
),
tags$script(
"const $regexHelp = $('#regex-format-help');
$regexHelp.popover({html: true});"
)
)
),
fluidRow(
id = "regexOptions",
checkboxGroupInput(
"regex_options",
label = HTML(
'',
"Option Groups: ",
'RegExplain,',
'All, ',
'Base only',
"
"
),
inline = TRUE,
width = "90%",
choiceValues = list(
"global",
"text_break_lines",
"ignore.case",
"fixed",
"perl",
"useBytes"
),
choiceNames = list(
HTML('Global'),
HTML('Break Lines'),
HTML('Ignore Case'),
HTML('Fixed/Literal'),
HTML('Perl Style'),
HTML('Use Bytes')
),
selected = c("text_break_lines", "perl")
)
),
tags$div(
id = "regexResult",
class = "gadget-result",
style = "overflow-y: scroll; height: 100%; max-height: calc(100% - 90px);",
htmlOutput("result")
)
)
)
),
# ---- UI - Tab - Output ----
miniTabPanel(
"Output",
icon = icon("table"),
miniContentPanel(
fillCol(
flex = c(1, 3),
inputPanel(
tags$div(
width = "100%",
selectInput(
"regexFn",
label = "Apply Function",
choices = regexFn_choices
),
tags$span(
class = "help-block",
style = "font-size:1.25rem; margin-top:-10px; margin-bottom:0px; margin-left:4px;",
"Adjust options in RegEx tab"
)
),
uiOutput("output_sub")
),
# verbatimTextOutput('output_result', placeholder = TRUE)
tags$pre(
id = "output_result",
class = "shiny-text-output",
style = "overflow-y: scroll; height: 100%;"
)
)
)
),
# ---- UI - Tab - Help ----
miniTabPanel(
"Help",
icon = icon("support"),
generate_help_ui(cheatsheet_only = FALSE)
)
)
)
}