| Author | DaveJarvis <email> |
|---|---|
| Date | 2021-12-12 19:17:39 GMT-0800 |
| Commit | 10d1f2c0773b01c17e5113f63d7990bf8ae56d36 |
| Parent | fac56be |
| * editor's directory; {@code false} means to export only the | ||
| * actively edited file. | ||
| + * | ||
| private void file_export_pdf( final Path theme, final boolean concat ) { | ||
| if( Typesetter.canRun() ) { | ||
| file_export( MARKDOWN_PLAIN ); | ||
| } | ||
| - */ | ||
| - | ||
| +*/ | ||
| /** | ||
| * Concatenates all the files in the same directory as the given file into | ||
| package com.keenwrite; | ||
| +import com.keenwrite.cmdline.HeadlessApp; | ||
| import com.keenwrite.events.HyperlinkOpenEvent; | ||
| import com.keenwrite.preferences.Workspace; | ||
| /** | ||
| - * Application entry point. | ||
| + * GUI application entry point. See {@link HeadlessApp} for the entry | ||
| + * point to the command-line application. | ||
| * | ||
| * @param args Command-line arguments. | ||
| final var editor = getActiveTextEditor(); | ||
| final var mediaType = editor.getMediaType(); | ||
| - final var operator = getSigilOperator( mediaType ); | ||
| + final var operator = createSigilOperator( mediaType ); | ||
| DefinitionNameInjector.autoinsert( editor, definitions, operator ); | ||
| * @param mediaType The type of file being edited. | ||
| */ | ||
| - private SigilOperator getSigilOperator( final MediaType mediaType ) { | ||
| + private SigilOperator createSigilOperator( final MediaType mediaType ) { | ||
| final var operator = new YamlSigilOperator( createDefinitionSigils() ); | ||
| private SetProperty<String> getRecentFiles() { | ||
| return getWorkspace().setsProperty( KEY_UI_FILES_PATH ); | ||
| - } | ||
| - | ||
| - private StringProperty stringProperty( final Key key ) { | ||
| - return getWorkspace().stringProperty( key ); | ||
| } | ||
| } | ||
| - private Sigils createSigils( final Key began, final Key ended ) { | ||
| - return new Sigils( stringProperty( began ), stringProperty( ended ) ); | ||
| + private Sigils createSigils( final Key keyBegan, final Key keyEnded ) { | ||
| + return getWorkspace().createSigils( keyBegan, keyEnded ); | ||
| } | ||
| } | ||
| import com.keenwrite.AppCommands; | ||
| +import com.keenwrite.events.StatusEvent; | ||
| +import org.greenrobot.eventbus.Subscribe; | ||
| + | ||
| +import static com.keenwrite.events.Bus.register; | ||
| /** | ||
| * Responsible for running the application in headless mode. | ||
| */ | ||
| public class HeadlessApp { | ||
| + | ||
| + /** | ||
| + * Contains directives that control text file processing. | ||
| + */ | ||
| + private final Arguments mArgs; | ||
| + | ||
| + /** | ||
| + * Creates a new command-line version of the application. | ||
| + * | ||
| + * @param args The post-processed command-line arguments. | ||
| + */ | ||
| + public HeadlessApp( final Arguments args ) { | ||
| + assert args != null; | ||
| + | ||
| + mArgs = args; | ||
| + | ||
| + register( this ); | ||
| + AppCommands.run( mArgs ); | ||
| + } | ||
| + | ||
| + /** | ||
| + * When a status message is shown, write it to the console, if not in | ||
| + * quiet mode. | ||
| + * | ||
| + * @param event The event published when the status changes. | ||
| + */ | ||
| + @Subscribe | ||
| + public void handle( final StatusEvent event ) { | ||
| + if( !mArgs.quiet() ) { | ||
| + System.out.println( event ); | ||
| + } | ||
| + } | ||
| /** | ||
| * Entry point for running the application in headless mode. | ||
| * | ||
| * @param args The parsed command-line arguments. | ||
| */ | ||
| public static void main( final Arguments args ) { | ||
| - AppCommands.run( args ); | ||
| + new HeadlessApp( args ); | ||
| } | ||
| } |
| package com.keenwrite.events; | ||
| -import com.keenwrite.MainApp; | ||
| +import com.keenwrite.AppCommands; | ||
| import java.util.List; | ||
| */ | ||
| public final class StatusEvent implements AppEvent { | ||
| - private static final String PACKAGE_NAME = MainApp.class.getPackageName(); | ||
| + /** | ||
| + * Reference a class in the top-level package that doesn't depend on any | ||
| + * JavaFX APIs. | ||
| + */ | ||
| + private static final String PACKAGE_NAME = AppCommands.class.getPackageName(); | ||
| private static final String ENGLISHIFY = | ||
| } | ||
| - public Sigils toSigils( final Key began, final Key ended ) { | ||
| - assert began != null; | ||
| - assert ended != null; | ||
| - return new Sigils( stringProperty( began ), stringProperty( ended ) ); | ||
| + public Sigils createSigils( final Key keyBegan, final Key keyEnded ) { | ||
| + assert keyBegan != null; | ||
| + assert keyEnded != null; | ||
| + | ||
| + return new Sigils( toString( keyBegan ), toString( keyEnded ) ); | ||
| } | ||
| private SigilOperator createSigilOperator( final Workspace workspace ) { | ||
| - final var tokens = workspace.toSigils( | ||
| + final var tokens = workspace.createSigils( | ||
| KEY_R_DELIM_BEGAN, KEY_R_DELIM_ENDED ); | ||
| final var antecedent = createDefinitionOperator( workspace ); | ||
| return new RSigilOperator( tokens, antecedent ); | ||
| } | ||
| private SigilOperator createDefinitionOperator( final Workspace workspace ) { | ||
| - final var sigils = workspace.toSigils( | ||
| + final var sigils = workspace.createSigils( | ||
| KEY_DEF_DELIM_BEGAN, KEY_DEF_DELIM_ENDED ); | ||
| return new YamlSigilOperator( sigils ); |
| package com.keenwrite.sigils; | ||
| -import javafx.beans.property.SimpleStringProperty; | ||
| - | ||
| import java.util.function.UnaryOperator; | ||
| */ | ||
| public SigilOperator( final String began, final String ended ) { | ||
| - this( new Sigils( | ||
| - new SimpleStringProperty( began ), | ||
| - new SimpleStringProperty( ended ) | ||
| - ) ); | ||
| + this( new Sigils( began, ended ) ); | ||
| } | ||
| * Convenience class for pairing a start and an end sigil together. | ||
| */ | ||
| -public final class Sigils | ||
| - extends SimpleImmutableEntry<StringProperty, StringProperty> { | ||
| +public final class Sigils extends SimpleImmutableEntry<String, String> { | ||
| /** | ||
| * Associates a new key-value pair. | ||
| * | ||
| * @param began The starting sigil. | ||
| * @param ended The ending sigil. | ||
| */ | ||
| - public Sigils( final StringProperty began, final StringProperty ended ) { | ||
| + public Sigils( final String began, final String ended ) { | ||
| super( began, ended ); | ||
| } | ||
| /** | ||
| * @return The opening sigil token. | ||
| */ | ||
| public String getBegan() { | ||
| - return getKey().get(); | ||
| + return getKey(); | ||
| } | ||
| /** | ||
| * @return The closing sigil token, or the empty string if none set. | ||
| */ | ||
| public String getEnded() { | ||
| - return getValue().get(); | ||
| + return getValue(); | ||
| } | ||
| } |
| final var began = new SimpleStringProperty( DEF_DELIM_BEGAN_DEFAULT ); | ||
| final var ended = new SimpleStringProperty( DEF_DELIM_ENDED_DEFAULT ); | ||
| - final var sigils = new Sigils( began, ended ); | ||
| + final var sigils = new Sigils( began.get(), ended.get() ); | ||
| final var operator = new YamlSigilOperator( sigils ); | ||
| final var transformer = new YamlTreeTransformer(); |
| package com.keenwrite.sigils; | ||
| -import javafx.beans.property.SimpleStringProperty; | ||
| -import javafx.beans.property.StringProperty; | ||
| import org.junit.jupiter.api.Test; | ||
| final var actual = mOperator.apply( "v$a$b$c$d" ); | ||
| assertEquals( expected, actual ); | ||
| - } | ||
| - | ||
| - private StringProperty createSigil( final String token ) { | ||
| - return new SimpleStringProperty( token ); | ||
| } | ||
| private Sigils createSigils( final String began, final String ended ) { | ||
| - return new Sigils( createSigil( began ), createSigil( ended ) ); | ||
| + return new Sigils( began, ended ); | ||
| } | ||
| Delta | 66 lines added, 39 lines removed, 27-line increase |
|---|