oriches / Simple.Wpf.Terminal

A simple console\terminal window for use in a WPF application
MIT License
101 stars 23 forks source link

Key processing issues #6

Open john10e opened 10 years ago

john10e commented 10 years ago

When I hit an enter key after typing a command the HandleEnterKey does not seem to capture the line. AggregateAfterPrompt() seems to always return an empty line.

I've installed the latest from NUGET version 1.29 and setup a sample similar to the examples you demonstrated. Seems to be the same problem as the last comment entered here: http://awkwardcoder.blogspot.co.uk/2014/01/simple-f-repl-in-wpf-part-4.html

oriches commented 10 years ago

which OS are you building for?

john10e commented 10 years ago

Windows 8 x64

From: Ollie Riches [mailto:notifications@github.com] Sent: Monday, September 15, 2014 3:00 PM To: oriches/Simple.Wpf.Terminal Cc: John Tenney Subject: Re: [Simple.Wpf.Terminal] Key processing issues (#6)

which OS are you building for?

— Reply to this email directly or view it on GitHubhttps://github.com/oriches/Simple.Wpf.Terminal/issues/6#issuecomment-55665728.

john10e commented 10 years ago

Also if I paste a command into the terminal with a CR-LF it seems to work. I hope that helps.

From: Ollie Riches [mailto:notifications@github.com] Sent: Monday, September 15, 2014 3:00 PM To: oriches/Simple.Wpf.Terminal Cc: John Tenney Subject: Re: [Simple.Wpf.Terminal] Key processing issues (#6)

which OS are you building for?

— Reply to this email directly or view it on GitHubhttps://github.com/oriches/Simple.Wpf.Terminal/issues/6#issuecomment-55665728.

oriches commented 10 years ago

I presume the OS is patched with the latest hotfixes via windows update.

Can you tell me the versions of the PresentationCore.dll, PresentationFramework.dll & System.Windows.Interactivity.dll referenced in the project?

john10e commented 10 years ago

Yes – the Win8 x64 OS is set to auto-update per our network policy.

PresentationCore.dll: 4.0.30319.18402 PresentationFramework.dll: 4.0.30319.18402 System.Windows.Interactivity: 3.0.40218.0

I will set my program up on a Win7 machine and report back the results.

BTW- I really like this library you created!

-John

From: Ollie Riches [mailto:notifications@github.com] Sent: Tuesday, September 16, 2014 1:49 AM To: oriches/Simple.Wpf.Terminal Cc: John Tenney Subject: Re: [Simple.Wpf.Terminal] Key processing issues (#6)

I presume the OS is patched with the latest hotfixes via windows update.

Can you tell me the versions of the PresentationCore.dll, PresentationFramework.dll & System.Windows.Interactivity.dll referenced in the project?

— Reply to this email directly or view it on GitHubhttps://github.com/oriches/Simple.Wpf.Terminal/issues/6#issuecomment-55713504.

john10e commented 10 years ago

I setup my application via click-once to run on a Win7 SP1 x64 laptop and I get the same result. Lines will appear via device/databinding but when I type into Terminal at the cursor and press enter, the HandleEnter event fires but consistently returns an empty line as a parameter.

I’ve attached the related view/viewmodels from my application. Perhaps I have Terminal configured wrong…

From: Ollie Riches [mailto:notifications@github.com] Sent: Tuesday, September 16, 2014 1:49 AM To: oriches/Simple.Wpf.Terminal Cc: John Tenney Subject: Re: [Simple.Wpf.Terminal] Key processing issues (#6)

I presume the OS is patched with the latest hotfixes via windows update.

Can you tell me the versions of the PresentationCore.dll, PresentationFramework.dll & System.Windows.Interactivity.dll referenced in the project?

— Reply to this email directly or view it on GitHubhttps://github.com/oriches/Simple.Wpf.Terminal/issues/6#issuecomment-55713504.

oriches commented 10 years ago

Where are the attachments, I'm not seeing them?

john10e commented 10 years ago

I’ve attached them again to this email. I wonder since we’re communicating via github it’s stripping off the attachments?

Here’s a pic of the original email w/ attachments I sent before:

[cid:image001.png@01CFD19C.8D8C9DE0]

From: Ollie Riches [mailto:notifications@github.com] Sent: Tuesday, September 16, 2014 10:51 AM To: oriches/Simple.Wpf.Terminal Cc: John Tenney Subject: Re: [Simple.Wpf.Terminal] Key processing issues (#6)

Where are the attachments, I'm not seeing them?

— Reply to this email directly or view it on GitHubhttps://github.com/oriches/Simple.Wpf.Terminal/issues/6#issuecomment-55783840.

oriches commented 10 years ago

I'm still not seeing them, can you paste the xaml & code direct into a comment?

john10e commented 10 years ago

I just created a small sample app reproducing the problem with Terminal that you can download from our ftp server: ftp://ftp.ptagis.org/Utilities/TerminalTest.zip

Here’s what the xaml looks like:

<Window x:Class="TerminalTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:terminal="clr-namespace:Simple.Wpf.Terminal;assembly=Simple.Wpf.Terminal" xmlns:ignore="http://www.ignore.com" mc:Ignorable="d ignore" Height="300" Width="300" Title="Test Terminal" DataContext="{Binding Main, Source={StaticResource Locator}}">

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Skins/MainSkin.xaml" />
            <ResourceDictionary Source="/Simple.Wpf.Terminal.Themes;component/DarkTheme.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>

<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition Height="35"/>
    </Grid.RowDefinitions>

    <terminal:Terminal  x:Name="TerminalOutput"
        Margin="5"
        IsReadOnlyCaretVisible="False"
        VerticalScrollBarVisibility="Visible"
        Prompt="{Binding Path=Prompt, Mode=OneWay}"
        IsReadOnly="{Binding Path=IsReadOnly, Mode=OneWay}"
        ItemsSource="{Binding Path=DeviceOutput, Mode=OneWay}">

        <terminal:Terminal.InputBindings>
            <KeyBinding Command="{Binding Path=ClearCommand, Mode=OneWay}"
                Gesture="CTRL+E" />
            <KeyBinding Command="{Binding Path=ResetCommand, Mode=OneWay}"
                Gesture="CTRL+R" />
            <KeyBinding Command="{x:Null}"
                Gesture="CTRL+L" />
        </terminal:Terminal.InputBindings>

        <!--<terminal:Terminal.ContextMenu>
            <ContextMenu>
                <MenuItem Header="Clear"
              InputGestureText="Ctrl+E"
              Command="{Binding Path=ClearCommand, Mode=OneWay}" />
                <MenuItem Header="Reset"
              InputGestureText="Ctrl+R"
              Command="{Binding Path=ResetCommand, Mode=OneWay}" />
                <Separator />
                <MenuItem Header="Copy"
              InputGestureText="Ctrl+C"
              Command="ApplicationCommands.Copy" />
                <MenuItem Header="Paste"
              InputGestureText="Ctrl+V"
              Command="ApplicationCommands.Paste" />
            </ContextMenu>
        </terminal:Terminal.ContextMenu>-->
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="LineEntered">
                <i:InvokeCommandAction Command="{Binding Path=ExecuteCommand, Mode=OneWay}"
                   CommandParameter="{Binding Path=Line, Mode=OneWay, ElementName=TerminalOutput}" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </terminal:Terminal>

    <StackPanel Orientation="Horizontal" Grid.Row="1">
        <Label Content="Command to Execute:"/>
        <TextBlock Text="{Binding CommandText, Mode=TwoWay}"/>
    </StackPanel>
</Grid>

From: Ollie Riches [mailto:notifications@github.com] Sent: Tuesday, September 16, 2014 11:24 AM To: oriches/Simple.Wpf.Terminal Cc: John Tenney Subject: Re: [Simple.Wpf.Terminal] Key processing issues (#6)

I'm still not seeing them, can you paste the xaml & code direct into a comment?

— Reply to this email directly or view it on GitHubhttps://github.com/oriches/Simple.Wpf.Terminal/issues/6#issuecomment-55789430.

john10e commented 10 years ago

Here’s the accompanying ViewModel code: ///

/// This class contains properties that the main View can data bind to.
/// <para>
/// See http://www.galasoft.ch/mvvm
/// </para>
/// </summary>

public class MainViewModel : ViewModelBase
{
    private string _commandText;
    /// <summary>
    /// Initializes a new instance of the MainViewModel class.
    /// </summary>
    public MainViewModel()
    {
        _commandText = string.Empty;
        ExecuteCommand = new RelayCommand<string>(OnExecuteCommand);
    }

    public string Prompt { get { return ">"; } }

    public bool IsReadOnly { get { return false; } }

    public ObservableCollection<string> DeviceOutput { get; private set; }

    public RelayCommand<string> ExecuteCommand { get; set; }

    public string CommandText
    {
        get { return _commandText; }
        set
        {
            Set(() => CommandText, ref _commandText, value);
        }
    }

    private void OnExecuteCommand(string commandText)
    {
        CommandText = commandText;
    }
    ////public override void Cleanup()
    ////{
    ////    // Clean up if needed

    ////    base.Cleanup();
    ////}
}

From: Ollie Riches [mailto:notifications@github.com] Sent: Tuesday, September 16, 2014 11:24 AM To: oriches/Simple.Wpf.Terminal Cc: John Tenney Subject: Re: [Simple.Wpf.Terminal] Key processing issues (#6)

I'm still not seeing them, can you paste the xaml & code direct into a comment?

— Reply to this email directly or view it on GitHubhttps://github.com/oriches/Simple.Wpf.Terminal/issues/6#issuecomment-55789430.

oriches commented 10 years ago

I've created an example WPF using the control and added it to github.

Could you download the zip of the code base and tell me if it works for you?

oriches commented 10 years ago

This is a screenshot of the loaded assemblies in the Simple.Wpf.Terminal.Example.

I can see I'm running later versions of the assemblies:

PresentationCore.dll 4.0.30319.34004 PresentationFramework.dll 4.00.30319.34004 System.Windows.Interactivity.dll 2.00.20525.0

image

john10e commented 10 years ago

Same behavior: I type in the word TEST and hit RETURN and nothing is added to the output. I put in a breakpoint in the ExampleViewModel.AddItem and the item parameter is an empty string.

From: Ollie Riches [mailto:notifications@github.com] Sent: Tuesday, September 16, 2014 12:36 PM To: oriches/Simple.Wpf.Terminal Cc: John Tenney Subject: Re: [Simple.Wpf.Terminal] Key processing issues (#6)

I've created an example WPF using the control and added it to github.

Could you download the zip of the code base and tell me if it works for you?

— Reply to this email directly or view it on GitHubhttps://github.com/oriches/Simple.Wpf.Terminal/issues/6#issuecomment-55800970.

john10e commented 10 years ago

I gave you bad information previously. Our loaded assemblies match: modules

Here's what the output looks like after typing TESTING and pressing RETURN: testingterminal

oriches commented 10 years ago

Okay, I've managed to get your code working, but there are a couple of mistakes.

  1. Constructor not creating the DeviceOutput collection,
  2. The command execute method need to add the new line to the DeviceOutput collection,

public class MainViewModel : ViewModelBase { private string _commandText;

public MainViewModel()
{
    _commandText = string.Empty;
    DeviceOutput = new ObservableCollection<string>();
    ExecuteCommand = new RelayCommand<string>(OnExecuteCommand);
}

public string Prompt { get { return ">"; } }

public bool IsReadOnly { get { return false; } }

public ObservableCollection<string> DeviceOutput { get; private set; }

public RelayCommand<string> ExecuteCommand { get; set; }

public string CommandText
{
    get { return _commandText; }
    set
    {
        Set(() => CommandText, ref _commandText, value);
    }
}

private void OnExecuteCommand(string commandText)
{
    DeviceOutput.Add(commandText);

    CommandText = commandText;
}

}

oriches commented 10 years ago

Could you take the screen shot of the loaded modules again and order them by Path for me so I can compare and look for any differences?

thanks

Ollie.

john10e commented 10 years ago

Here it is (I have a different working folder so they'll be off slightly): modules

john10e commented 10 years ago

ASLO: I fixed the mistakes in my sample but still getting empty string passed in as command parameter...

oriches commented 10 years ago

sorry, could you do it again, order by Path but expand the version column so I can see the full version of the assembly :)

john10e commented 10 years ago

No problem: modules

john10e commented 10 years ago

More information: I put a breakpoint in your Example WPF Terminal.HandleEnterKey() - typed in the TESTING and let it call var line = AggregrateAfterPrompt(); As you can see in Locals the line = ""';

breakterminal

Here's the Window after ENTER pressed: testingterminal

john10e commented 10 years ago

Ollie: I had my colleague download and try the example - he gets the same behavior has me. Since It's getting late on your side of the pond this can wait if need be.

oriches commented 10 years ago

I've added some debugging to the codebase could you down load and run the example app in debug mode. What I get is shown below.

yeah it is getting late (10:00 pm), I'll have a look at work tomorrow if I get a spare hour.

image

john10e commented 10 years ago

I've put the debug output here: ftp://ftp.ptagis.org/Utilities/TerminalDebugOutput.txt.

Looking at your screenshot above, shouldn't the 'some text' have been added to the output above the prompt after the ENTER key was pressed and then the prompt would be cleared? That's my understanding of how Terminal executes commands.

oriches commented 10 years ago

I've updated the debugging in Terminal.cs, can you re-run the test and paste the debug output.

It looks like there isn't an instance of an Inline class after the Prompt Inline is inserted.

oriches commented 10 years ago

I've updated Termiinal.cs again with a possible fix for the issue.

Can you test and paste the debug output.

john10e commented 10 years ago

I think it’s closer. I’ve gone ahead and updated the debug output from the last ftp link I sent you.

First ENTER after ‘TEST’ doesn’t seem to work, but subsequent typing and ENTER does. It still appears the backspace/delete keys are not working however.

oriches commented 10 years ago

Updated Terminal.cs again, can you test and paste the debug output.

john10e commented 10 years ago

Done – see debug output on ftp.

oriches commented 10 years ago

running out of ideas - it appears something to do with the FlowDocument inside the RichTextBox and the CaretPosition.

I've made another subtle change, can you test and paste the debug output.

john10e commented 10 years ago

OK – I updated the debug file and tested with a pasted line from the Clipboard.

No problem dropping this. I’m not that familiar with FlowDocument/RichTextBox. When I get some time (one day?) I’ll brush up and see if I can come up with something.

I truly appreciate the effort!