Ejemplo n.º 1
0
        static void Main(string[] args)
        {
//            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");
            RimeTraits traits = new RimeTraits();

            traits.app_name = "YIME.PlayGround";

            Rime.RimeSetup(ref traits);
            Console.WriteLine("初始化1");
            Rime.RimeInitialize(IntPtr.Zero);
            Console.WriteLine("初始化2");
            Rime.RimeSetNotificationHandler(Handler, IntPtr.Zero);
            if (Rime.RimeStartMaintenance(true))
            {
                Rime.RimeJoinMaintenanceThread();
            }


            var rimesessionid = Rime.RimeCreateSession();

            Console.WriteLine("Session ID: " + rimesessionid);


            while (true)
            {
                var key = Console.ReadKey();
                if (key.Key == ConsoleKey.Escape)
                {
                    break;
                }
                Console.WriteLine();
                Rime.RimeSimulateKeySequence(rimesessionid, key.KeyChar.ToString());

                var commit  = new RimeCommit();
                var status  = new RimeStatus();
                var context = new RimeContext();
                commit.Init();
                status.Init();
                context.Init();

                Rime.RimeGetCommit(rimesessionid, ref commit);
                Rime.RimeGetStatus(rimesessionid, ref status);
                Rime.RimeGetContext(rimesessionid, ref context);
                Console.WriteLine("Commit:" + commit.text);
                Console.WriteLine($"Status: {status.is_composing},{status.is_ascii_mode}, {status.schema_name}");
                Console.WriteLine($"Context: {context.commit_text_preview}, {context.composition.preedit}");
                var candiates =
                    RimeApi.Common.StuctArrayFromIntPtr <RimeCandidate>(context.menu.candidates,
                                                                        context.menu.num_candidates);
                for (int i = 0; i < context.menu.num_candidates; i++)
                {
                    Console.WriteLine($"{i+1}: {candiates[i].text}");
                }
            }
        }
Ejemplo n.º 2
0
        string update()
        {
            var commit  = new RimeCommit();
            var status  = new RimeStatus();
            var context = new RimeContext();

            commit.Init();
            status.Init();
            context.Init();

            Rime.RimeGetCommit(rimesessionid, ref commit);
            Rime.RimeGetStatus(rimesessionid, ref status);
            Rime.RimeGetContext(rimesessionid, ref context);
            if (!string.IsNullOrEmpty(commit.text))
            {
                this.tb.Text    = "";
                this.lb.Content = commit.text;
            }
            if (status.is_composing)
            {
                this.lb.Content = context.composition.preedit;
                var candiates =
                    RimeApi.Common.StuctArrayFromIntPtr <RimeCandidate>(context.menu.candidates,
                                                                        context.menu.num_candidates);
                sblist.Clear();

                for (int i = 0; i < context.menu.num_candidates; i++)
                {
                    sblist.Add(candiates[i].text);
                }
                updatelistdisplay();
            }
            else
            {
                this.tb.Text = "";
            }

            return(context.composition.preedit);
        }